Library MonadVM.Gas
File generated by rocq-of-ocaml
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import RocqOfOCaml.Settings.
Require Import MonadVM.Support.UintN.
Require MonadVM.Byte_string.
Require MonadVM.Chain.Ethereum.
Require MonadVM.Chain.Monad.
Require MonadVM.Delegation.
Require MonadVM.Numeric.
Require MonadVM.Rlp.
Require Import MonadVM.Support.Variants.
Require MonadVM.Support.CryptoBlake2.
Require Import RocqOfOCaml.Opaque.
Local Ltac _rocq_witness_type typ :=
let typ := eval hnf in typ in
lazymatch typ with
| list ?a ⇒ let a := _rocq_witness_type a in constr:(list a)
| option ?a ⇒ let a := _rocq_witness_type a in constr:(option a)
| prod ?a ?b ⇒ let a := _rocq_witness_type a in
let b := _rocq_witness_type b in constr:(prod a b)
| sum ?a ?b ⇒ let a := _rocq_witness_type a in
let b := _rocq_witness_type b in constr:(sum a b)
| ?a → ?b ⇒ let a := _rocq_witness_type a in
let b := _rocq_witness_type b in constr:(a → b)
| _ ⇒ typ
end.
Definition Impl := MonadVM.Support.UintN.Impl.
Definition t := MonadVM.Support.UintN.t.
Definition signed := MonadVM.Support.UintN.signed.
Definition max_t := MonadVM.Support.UintN.max_t.
Definition min_t := MonadVM.Support.UintN.min_t.
Definition in_range := MonadVM.Support.UintN.in_range.
Definition of_z_opt := MonadVM.Support.UintN.of_z_opt.
Definition of_z_truncating := MonadVM.Support.UintN.of_z_truncating.
Definition to_z := MonadVM.Support.UintN.to_z.
Definition testbit := MonadVM.Support.UintN.testbit.
Definition of_z_exn := MonadVM.Support.UintN.of_z_exn.
Definition zero := MonadVM.Support.UintN.zero.
Definition one := MonadVM.Support.UintN.one.
Definition byte := MonadVM.Support.UintN.byte.
Definition significant_bits := MonadVM.Support.UintN.significant_bits.
Definition significant_bytes := MonadVM.Support.UintN.significant_bytes.
Definition of_bool := MonadVM.Support.UintN.of_bool.
Definition of_byte := MonadVM.Support.UintN.of_byte.
Definition of_int := MonadVM.Support.UintN.of_int.
Definition op_tildedollar := MonadVM.Support.UintN.op_tildedollar.
Definition to_int := MonadVM.Support.UintN.to_int.
Definition to_int_opt := MonadVM.Support.UintN.to_int_opt.
Definition of_uint64 := MonadVM.Support.UintN.of_uint64.
Definition of_int64 := MonadVM.Support.UintN.of_int64.
Definition to_uint64 := MonadVM.Support.UintN.to_uint64.
Definition to_int64 := MonadVM.Support.UintN.to_int64.
Definition of_uint32 := MonadVM.Support.UintN.of_uint32.
Definition of_int32 := MonadVM.Support.UintN.of_int32.
Definition to_uint32 := MonadVM.Support.UintN.to_uint32.
Definition to_int32 := MonadVM.Support.UintN.to_int32.
Definition hash := MonadVM.Support.UintN.hash.
Definition comparison_op := MonadVM.Support.UintN.comparison_op.
Definition op_lt := MonadVM.Support.UintN.op_lt.
Definition op_lteq := MonadVM.Support.UintN.op_lteq.
Definition op_eq := MonadVM.Support.UintN.op_eq.
Definition op_gteq := MonadVM.Support.UintN.op_gteq.
Definition op_gt := MonadVM.Support.UintN.op_gt.
Definition op_ltgt := MonadVM.Support.UintN.op_ltgt.
Definition equal := MonadVM.Support.UintN.equal.
Definition compare := MonadVM.Support.UintN.compare.
Definition max := MonadVM.Support.UintN.max.
Definition min := MonadVM.Support.UintN.min.
Definition _Set := MonadVM.Support.UintN._Set.
Definition is_zero := MonadVM.Support.UintN.is_zero.
Definition to_string := MonadVM.Support.UintN.to_string.
Definition to_hex_string := MonadVM.Support.UintN.to_hex_string.
Definition of_string := MonadVM.Support.UintN.of_string.
Definition op_tildeat := MonadVM.Support.UintN.op_tildeat.
Definition Map := MonadVM.Support.UintN.Map.
Definition of_z_after_op := MonadVM.Support.UintN.of_z_after_op.
Definition lift_1 := MonadVM.Support.UintN.lift_1.
Definition lift_2 := MonadVM.Support.UintN.lift_2.
Definition logand := MonadVM.Support.UintN.logand.
Definition logor := MonadVM.Support.UintN.logor.
Definition logxor := MonadVM.Support.UintN.logxor.
Definition lognot := MonadVM.Support.UintN.lognot.
Definition op_plus := MonadVM.Support.UintN.op_plus.
Definition op_minus := MonadVM.Support.UintN.op_minus.
Definition op_star := MonadVM.Support.UintN.op_star.
Definition op_div := MonadVM.Support.UintN.op_div.
Definition modulo := MonadVM.Support.UintN.modulo.
Definition rem := MonadVM.Support.UintN.rem.
Definition addmod := MonadVM.Support.UintN.addmod.
Definition mulmod := MonadVM.Support.UintN.mulmod.
Definition shift_left := MonadVM.Support.UintN.shift_left.
Definition shift_right := MonadVM.Support.UintN.shift_right.
Definition op_starstar := MonadVM.Support.UintN.op_starstar.
Definition exp_mod := MonadVM.Support.UintN.exp_mod.
Definition minus_1_64th := MonadVM.Support.UintN.minus_1_64th.
Definition bytes_to_whole_words := MonadVM.Support.UintN.bytes_to_whole_words.
Definition as_signed := MonadVM.Support.UintN.as_signed.
Definition of_bytes_be := MonadVM.Support.UintN.of_bytes_be.
Definition to_bytes_be := MonadVM.Support.UintN.to_bytes_be.
Definition of_rlp := MonadVM.Support.UintN.of_rlp.
Definition to_rlp := MonadVM.Support.UintN.to_rlp.
Definition ceil_div := MonadVM.Support.UintN.ceil_div.
Definition div_rem := MonadVM.Support.UintN.div_rem.
Definition _rocq_fallback_updated_base_fee_per_gas_0 :
ltac:(let typ := constr:(ltac:(first [unshelve refine ((t)%type
)]; first [match goal with |- ?g ⇒ let sort := type of g in lazymatch sort with Set ⇒ fail | _ ⇒ shelve end end | eassumption | typeclasses eauto | RocqOfOCaml.Opaque.opaque_inhabit 64%nat])) in let typ := _rocq_witness_type typ in exact typ).
Proof. unshelve (RocqOfOCaml.Opaque.opaque_inhabit 64%nat). all: RocqOfOCaml.Opaque.opaque_inhabit 64%nat. Qed.
Definition updated_base_fee_per_gas
(parent_header : MonadVM.Chain.Ethereum.Block.Header.t)
: MonadVM.Support.UintN.t :=
let elasticity_multiplier := op_tildedollar 2 in
let base_fee_max_change_denominator := op_tildedollar 8 in
let base_fee :=
parent_header.(MonadVM.Chain.Ethereum.Block.Header.t.base_fee_per_gas) in
let gas_used := parent_header.(MonadVM.Chain.Ethereum.Block.Header.t.gas_used)
in
let gas_target :=
op_div parent_header.(MonadVM.Chain.Ethereum.Block.Header.t.gas_limit)
elasticity_multiplier in
match
(tt,
(let '_ := tt in
op_eq gas_used gas_target),
(let '_ := tt in
op_lt gas_used gas_target),
(let '_ := tt in
op_gt gas_used gas_target)) with
| (_, true, _, _) ⇒ base_fee
| (_, _, true, _) ⇒
let base_fee_decrease_star :=
op_div (op_star base_fee (op_minus gas_target gas_used)) gas_target in
let base_fee_decrease :=
op_div base_fee_decrease_star base_fee_max_change_denominator in
op_minus base_fee base_fee_decrease
| (_, _, _, true) ⇒
let base_fee_increase_star :=
op_div (op_star base_fee (op_minus gas_used gas_target)) gas_target in
let base_fee_increase :=
max (op_div base_fee_increase_star base_fee_max_change_denominator) one in
op_plus base_fee base_fee_increase
| (_, _, _, _) ⇒
let '_ := false in
_rocq_fallback_updated_base_fee_per_gas_0
end.
Require Import RocqOfOCaml.Settings.
Require Import MonadVM.Support.UintN.
Require MonadVM.Byte_string.
Require MonadVM.Chain.Ethereum.
Require MonadVM.Chain.Monad.
Require MonadVM.Delegation.
Require MonadVM.Numeric.
Require MonadVM.Rlp.
Require Import MonadVM.Support.Variants.
Require MonadVM.Support.CryptoBlake2.
Require Import RocqOfOCaml.Opaque.
Local Ltac _rocq_witness_type typ :=
let typ := eval hnf in typ in
lazymatch typ with
| list ?a ⇒ let a := _rocq_witness_type a in constr:(list a)
| option ?a ⇒ let a := _rocq_witness_type a in constr:(option a)
| prod ?a ?b ⇒ let a := _rocq_witness_type a in
let b := _rocq_witness_type b in constr:(prod a b)
| sum ?a ?b ⇒ let a := _rocq_witness_type a in
let b := _rocq_witness_type b in constr:(sum a b)
| ?a → ?b ⇒ let a := _rocq_witness_type a in
let b := _rocq_witness_type b in constr:(a → b)
| _ ⇒ typ
end.
Definition Impl := MonadVM.Support.UintN.Impl.
Definition t := MonadVM.Support.UintN.t.
Definition signed := MonadVM.Support.UintN.signed.
Definition max_t := MonadVM.Support.UintN.max_t.
Definition min_t := MonadVM.Support.UintN.min_t.
Definition in_range := MonadVM.Support.UintN.in_range.
Definition of_z_opt := MonadVM.Support.UintN.of_z_opt.
Definition of_z_truncating := MonadVM.Support.UintN.of_z_truncating.
Definition to_z := MonadVM.Support.UintN.to_z.
Definition testbit := MonadVM.Support.UintN.testbit.
Definition of_z_exn := MonadVM.Support.UintN.of_z_exn.
Definition zero := MonadVM.Support.UintN.zero.
Definition one := MonadVM.Support.UintN.one.
Definition byte := MonadVM.Support.UintN.byte.
Definition significant_bits := MonadVM.Support.UintN.significant_bits.
Definition significant_bytes := MonadVM.Support.UintN.significant_bytes.
Definition of_bool := MonadVM.Support.UintN.of_bool.
Definition of_byte := MonadVM.Support.UintN.of_byte.
Definition of_int := MonadVM.Support.UintN.of_int.
Definition op_tildedollar := MonadVM.Support.UintN.op_tildedollar.
Definition to_int := MonadVM.Support.UintN.to_int.
Definition to_int_opt := MonadVM.Support.UintN.to_int_opt.
Definition of_uint64 := MonadVM.Support.UintN.of_uint64.
Definition of_int64 := MonadVM.Support.UintN.of_int64.
Definition to_uint64 := MonadVM.Support.UintN.to_uint64.
Definition to_int64 := MonadVM.Support.UintN.to_int64.
Definition of_uint32 := MonadVM.Support.UintN.of_uint32.
Definition of_int32 := MonadVM.Support.UintN.of_int32.
Definition to_uint32 := MonadVM.Support.UintN.to_uint32.
Definition to_int32 := MonadVM.Support.UintN.to_int32.
Definition hash := MonadVM.Support.UintN.hash.
Definition comparison_op := MonadVM.Support.UintN.comparison_op.
Definition op_lt := MonadVM.Support.UintN.op_lt.
Definition op_lteq := MonadVM.Support.UintN.op_lteq.
Definition op_eq := MonadVM.Support.UintN.op_eq.
Definition op_gteq := MonadVM.Support.UintN.op_gteq.
Definition op_gt := MonadVM.Support.UintN.op_gt.
Definition op_ltgt := MonadVM.Support.UintN.op_ltgt.
Definition equal := MonadVM.Support.UintN.equal.
Definition compare := MonadVM.Support.UintN.compare.
Definition max := MonadVM.Support.UintN.max.
Definition min := MonadVM.Support.UintN.min.
Definition _Set := MonadVM.Support.UintN._Set.
Definition is_zero := MonadVM.Support.UintN.is_zero.
Definition to_string := MonadVM.Support.UintN.to_string.
Definition to_hex_string := MonadVM.Support.UintN.to_hex_string.
Definition of_string := MonadVM.Support.UintN.of_string.
Definition op_tildeat := MonadVM.Support.UintN.op_tildeat.
Definition Map := MonadVM.Support.UintN.Map.
Definition of_z_after_op := MonadVM.Support.UintN.of_z_after_op.
Definition lift_1 := MonadVM.Support.UintN.lift_1.
Definition lift_2 := MonadVM.Support.UintN.lift_2.
Definition logand := MonadVM.Support.UintN.logand.
Definition logor := MonadVM.Support.UintN.logor.
Definition logxor := MonadVM.Support.UintN.logxor.
Definition lognot := MonadVM.Support.UintN.lognot.
Definition op_plus := MonadVM.Support.UintN.op_plus.
Definition op_minus := MonadVM.Support.UintN.op_minus.
Definition op_star := MonadVM.Support.UintN.op_star.
Definition op_div := MonadVM.Support.UintN.op_div.
Definition modulo := MonadVM.Support.UintN.modulo.
Definition rem := MonadVM.Support.UintN.rem.
Definition addmod := MonadVM.Support.UintN.addmod.
Definition mulmod := MonadVM.Support.UintN.mulmod.
Definition shift_left := MonadVM.Support.UintN.shift_left.
Definition shift_right := MonadVM.Support.UintN.shift_right.
Definition op_starstar := MonadVM.Support.UintN.op_starstar.
Definition exp_mod := MonadVM.Support.UintN.exp_mod.
Definition minus_1_64th := MonadVM.Support.UintN.minus_1_64th.
Definition bytes_to_whole_words := MonadVM.Support.UintN.bytes_to_whole_words.
Definition as_signed := MonadVM.Support.UintN.as_signed.
Definition of_bytes_be := MonadVM.Support.UintN.of_bytes_be.
Definition to_bytes_be := MonadVM.Support.UintN.to_bytes_be.
Definition of_rlp := MonadVM.Support.UintN.of_rlp.
Definition to_rlp := MonadVM.Support.UintN.to_rlp.
Definition ceil_div := MonadVM.Support.UintN.ceil_div.
Definition div_rem := MonadVM.Support.UintN.div_rem.
Definition _rocq_fallback_updated_base_fee_per_gas_0 :
ltac:(let typ := constr:(ltac:(first [unshelve refine ((t)%type
)]; first [match goal with |- ?g ⇒ let sort := type of g in lazymatch sort with Set ⇒ fail | _ ⇒ shelve end end | eassumption | typeclasses eauto | RocqOfOCaml.Opaque.opaque_inhabit 64%nat])) in let typ := _rocq_witness_type typ in exact typ).
Proof. unshelve (RocqOfOCaml.Opaque.opaque_inhabit 64%nat). all: RocqOfOCaml.Opaque.opaque_inhabit 64%nat. Qed.
Definition updated_base_fee_per_gas
(parent_header : MonadVM.Chain.Ethereum.Block.Header.t)
: MonadVM.Support.UintN.t :=
let elasticity_multiplier := op_tildedollar 2 in
let base_fee_max_change_denominator := op_tildedollar 8 in
let base_fee :=
parent_header.(MonadVM.Chain.Ethereum.Block.Header.t.base_fee_per_gas) in
let gas_used := parent_header.(MonadVM.Chain.Ethereum.Block.Header.t.gas_used)
in
let gas_target :=
op_div parent_header.(MonadVM.Chain.Ethereum.Block.Header.t.gas_limit)
elasticity_multiplier in
match
(tt,
(let '_ := tt in
op_eq gas_used gas_target),
(let '_ := tt in
op_lt gas_used gas_target),
(let '_ := tt in
op_gt gas_used gas_target)) with
| (_, true, _, _) ⇒ base_fee
| (_, _, true, _) ⇒
let base_fee_decrease_star :=
op_div (op_star base_fee (op_minus gas_target gas_used)) gas_target in
let base_fee_decrease :=
op_div base_fee_decrease_star base_fee_max_change_denominator in
op_minus base_fee base_fee_decrease
| (_, _, _, true) ⇒
let base_fee_increase_star :=
op_div (op_star base_fee (op_minus gas_used gas_target)) gas_target in
let base_fee_increase :=
max (op_div base_fee_increase_star base_fee_max_change_denominator) one in
op_plus base_fee base_fee_increase
| (_, _, _, _) ⇒
let '_ := false in
_rocq_fallback_updated_base_fee_per_gas_0
end.
The amount of gas provided for the execution of a system transaction. See EIP-2935, EIP-4788.
Gas cost per zero byte of the calldata. Non-zero bytes consume 4 times this amount. See G_txdatazero and
G_txdatanonzero in YP (64).
The minimum amount of gas consumed by a transaction for each zero byte of the calldata. Non-zero bytes
consume 4 times this amount. See EIP-7623.
Additional gas cost for contract creation transactions. See G_create in YP Appendix G.
Gas cost per 32-byte word of initcode in a deploy transaction or a CREATE or CREATE2 operation.
See G_initcodeword in YP Appendix G.
Gas cost per address in a transaction's access list.
Gas cost per storage key in a transaction's access list.
Base gas cost of a transaction.
Compute the amount of tokens in a transaction's calldata. A zero byte is counted as one token, a
non-zero byte is counted as 4 tokens.
Definition tokens_in_calldata (tx : MonadVM.Chain.Ethereum.Transaction.t)
: int :=
let '{|
MonadVM.Byte_string.Bytes.zero_and_nonzero_counts.zero_bytes := zero_bytes;
MonadVM.Byte_string.Bytes.zero_and_nonzero_counts.nonzero_bytes :=
nonzero_bytes
|} :=
MonadVM.Byte_string.Bytes.count_zero_and_nonzero_bytes
(MonadVM.Chain.Ethereum.Transaction.data tx) in
RocqOfOCaml.OCamlInt.add zero_bytes (RocqOfOCaml.OCamlInt.mul 4 nonzero_bytes).
: int :=
let '{|
MonadVM.Byte_string.Bytes.zero_and_nonzero_counts.zero_bytes := zero_bytes;
MonadVM.Byte_string.Bytes.zero_and_nonzero_counts.nonzero_bytes :=
nonzero_bytes
|} :=
MonadVM.Byte_string.Bytes.count_zero_and_nonzero_bytes
(MonadVM.Chain.Ethereum.Transaction.data tx) in
RocqOfOCaml.OCamlInt.add zero_bytes (RocqOfOCaml.OCamlInt.mul 4 nonzero_bytes).
EIP-7702: Cost of processing an authorization when the code of the authority is empty.
Definition tx_authorization_list_gas_per_address : MonadVM.Support.UintN.t :=
MonadVM.Delegation.per_empty_account_cost.
MonadVM.Delegation.per_empty_account_cost.
EIP-7702: Gas refund when processing an authorization when the code of the authority is empty.
As per the EIP, the full cost is subtracted first, as if the code was empty, and this amount is then
added to the refund counter.
Definition tx_authorization_list_refund_per_nonempty
: MonadVM.Support.UintN.t :=
op_minus MonadVM.Delegation.per_empty_account_cost
MonadVM.Delegation.per_auth_base_cost.
: MonadVM.Support.UintN.t :=
op_minus MonadVM.Delegation.per_empty_account_cost
MonadVM.Delegation.per_auth_base_cost.
tx_intrinsic_gas tx computes the intrinsic gas cost of tx, that is, the amount of gas that is charged
before execution starts. YP (64)
Definition tx_intrinsic_gas (tx : MonadVM.Chain.Ethereum.Transaction.t)
: MonadVM.Support.UintN.t :=
let calldata_gas :=
op_star (op_tildedollar (tokens_in_calldata tx)) tx_calldata_token_gas in
let create_gas :=
match MonadVM.Chain.Ethereum.Transaction.call_or_create_value tx with
| MonadVM.Chain.Ethereum.Transaction.Call _ ⇒ zero
|
MonadVM.Chain.Ethereum.Transaction.Create {|
MonadVM.Chain.Ethereum.Transaction.call_or_create.Create.initcode := initcode
|} ⇒
op_plus tx_create_gas
(op_star tx_initcode_gas_per_word
(bytes_to_whole_words
(op_tildedollar (MonadVM.Byte_string.Bytes.length initcode))))
end in
let transaction_gas := tx_base_gas in
let access_list_gas :=
RocqOfOCaml.OCamlList.fold_left
(fun (g_value : MonadVM.Support.UintN.t) ⇒
fun (access : MonadVM.Chain.Ethereum.Transaction.Access.t) ⇒
op_plus (op_plus g_value tx_access_list_address)
(op_star tx_access_list_storage
(op_tildedollar
(RocqOfOCaml.OCamlList.length
access.(MonadVM.Chain.Ethereum.Transaction.Access.t.storage_keys)))))
zero (MonadVM.Chain.Ethereum.Transaction.access_list tx) in
let authorization_list_gas :=
op_star tx_authorization_list_gas_per_address
(op_tildedollar
(RocqOfOCaml.OCamlList.length
(MonadVM.Chain.Ethereum.Transaction.authorization_list tx))) in
op_plus
(op_plus (op_plus (op_plus calldata_gas create_gas) transaction_gas)
access_list_gas) authorization_list_gas.
: MonadVM.Support.UintN.t :=
let calldata_gas :=
op_star (op_tildedollar (tokens_in_calldata tx)) tx_calldata_token_gas in
let create_gas :=
match MonadVM.Chain.Ethereum.Transaction.call_or_create_value tx with
| MonadVM.Chain.Ethereum.Transaction.Call _ ⇒ zero
|
MonadVM.Chain.Ethereum.Transaction.Create {|
MonadVM.Chain.Ethereum.Transaction.call_or_create.Create.initcode := initcode
|} ⇒
op_plus tx_create_gas
(op_star tx_initcode_gas_per_word
(bytes_to_whole_words
(op_tildedollar (MonadVM.Byte_string.Bytes.length initcode))))
end in
let transaction_gas := tx_base_gas in
let access_list_gas :=
RocqOfOCaml.OCamlList.fold_left
(fun (g_value : MonadVM.Support.UintN.t) ⇒
fun (access : MonadVM.Chain.Ethereum.Transaction.Access.t) ⇒
op_plus (op_plus g_value tx_access_list_address)
(op_star tx_access_list_storage
(op_tildedollar
(RocqOfOCaml.OCamlList.length
access.(MonadVM.Chain.Ethereum.Transaction.Access.t.storage_keys)))))
zero (MonadVM.Chain.Ethereum.Transaction.access_list tx) in
let authorization_list_gas :=
op_star tx_authorization_list_gas_per_address
(op_tildedollar
(RocqOfOCaml.OCamlList.length
(MonadVM.Chain.Ethereum.Transaction.authorization_list tx))) in
op_plus
(op_plus (op_plus (op_plus calldata_gas create_gas) transaction_gas)
access_list_gas) authorization_list_gas.
tx_floor_gas tx computes the floor gas cost of tx, as per EIP-7623. A transaction must provide enough
gas to cover this amount (before subtracting the intrinsic gas), but it is not charged. Instead, it is
used as a lower bound to the post-execution gas used counter. Monad transactions always use the full
amount of gas provided, so the floor gas is only used as a pre-execution check.
Definition tx_floor_gas (tx : MonadVM.Chain.Ethereum.Transaction.t)
: MonadVM.Support.UintN.t :=
op_plus
(op_star (op_tildedollar (tokens_in_calldata tx))
tx_calldata_floor_token_gas) tx_base_gas.
: MonadVM.Support.UintN.t :=
op_plus
(op_star (op_tildedollar (tokens_in_calldata tx))
tx_calldata_floor_token_gas) tx_base_gas.
tx_effective_gas_price b tx is the price in MON-wei that the sender of tx will pay per unit of gas.
YP (66), gas_bid in Monad §2
Definition tx_effective_gas_price
(base_fee_per_gas : MonadVM.Support.UintN.t)
(tx : MonadVM.Chain.Ethereum.Transaction.t)
: option MonadVM.Support.UintN.Impl.t :=
match MonadVM.Chain.Ethereum.Transaction.fee_mechanism_value tx with
|
MonadVM.Chain.Ethereum.Transaction.FeeMarketFee {|
MonadVM.Chain.Ethereum.Transaction.fee_mechanism.FeeMarketFee.max_fee_per_gas
:= max_fee_per_gas;
MonadVM.Chain.Ethereum.Transaction.fee_mechanism.FeeMarketFee.max_priority_fee_per_gas
:= max_priority_fee_per_gas
|} ⇒
if op_lt max_fee_per_gas max_priority_fee_per_gas then
None
else
Some
(min (op_plus max_priority_fee_per_gas base_fee_per_gas) max_fee_per_gas)
|
MonadVM.Chain.Ethereum.Transaction.LegacyFee {|
MonadVM.Chain.Ethereum.Transaction.fee_mechanism.LegacyFee.gas_price :=
gas_price
|} ⇒ Some gas_price
end.
(base_fee_per_gas : MonadVM.Support.UintN.t)
(tx : MonadVM.Chain.Ethereum.Transaction.t)
: option MonadVM.Support.UintN.Impl.t :=
match MonadVM.Chain.Ethereum.Transaction.fee_mechanism_value tx with
|
MonadVM.Chain.Ethereum.Transaction.FeeMarketFee {|
MonadVM.Chain.Ethereum.Transaction.fee_mechanism.FeeMarketFee.max_fee_per_gas
:= max_fee_per_gas;
MonadVM.Chain.Ethereum.Transaction.fee_mechanism.FeeMarketFee.max_priority_fee_per_gas
:= max_priority_fee_per_gas
|} ⇒
if op_lt max_fee_per_gas max_priority_fee_per_gas then
None
else
Some
(min (op_plus max_priority_fee_per_gas base_fee_per_gas) max_fee_per_gas)
|
MonadVM.Chain.Ethereum.Transaction.LegacyFee {|
MonadVM.Chain.Ethereum.Transaction.fee_mechanism.LegacyFee.gas_price :=
gas_price
|} ⇒ Some gas_price
end.
Maximum amount of gas a transaction is allowed to provide. If a transaction's gas limit exceeds this
amount, it is considered invalid. EIP-7825, adjusted for Monad §3 max_tx_gas_limit.
Definition tx_max_gas_limit : MonadVM.Support.UintN.t :=
op_tildedollar 30000000.
Definition jumpdest : MonadVM.Support.UintN.t := op_tildedollar 1.
Definition base : MonadVM.Support.UintN.t := op_tildedollar 2.
Definition very_low : MonadVM.Support.UintN.t := op_tildedollar 3.
Definition low : MonadVM.Support.UintN.t := op_tildedollar 5.
Definition mid : MonadVM.Support.UintN.t := op_tildedollar 8.
Definition high : MonadVM.Support.UintN.t := op_tildedollar 10.
Definition exp_base_cost : MonadVM.Support.UintN.t := op_tildedollar 10.
Definition exp_cost_per_byte : MonadVM.Support.UintN.t := op_tildedollar 50.
Definition keccak256_base_cost : MonadVM.Support.UintN.t := op_tildedollar 30.
Definition keccak256_cost_per_word : MonadVM.Support.UintN.t :=
op_tildedollar 6.
Definition log_cost : MonadVM.Support.UintN.t := op_tildedollar 375.
Definition log_cost_per_byte : MonadVM.Support.UintN.t := op_tildedollar 8.
Definition log_cost_per_topic : MonadVM.Support.UintN.t := op_tildedollar 375.
Definition self_destruct_cost : MonadVM.Support.UintN.t := op_tildedollar 5000.
Definition self_destruct_new_account_cost : MonadVM.Support.UintN.t :=
op_tildedollar 25000.
Definition new_account_cost : MonadVM.Support.UintN.t := op_tildedollar 25000.
Definition call_value : MonadVM.Support.UintN.t := op_tildedollar 9000.
Definition call_stipend : MonadVM.Support.UintN.t := op_tildedollar 2300.
Definition cold_sload_cost : MonadVM.Support.UintN.t := op_tildedollar 8100.
Definition cold_account_access_cost : MonadVM.Support.UintN.t :=
op_tildedollar 10100.
Definition warm_access_cost : MonadVM.Support.UintN.t := op_tildedollar 100.
Definition account_access_cost
(function_parameter : MonadVM.Support.Variants.AccessStatus.t)
: MonadVM.Support.UintN.t :=
match function_parameter with
| MonadVM.Support.Variants.AccessStatus.Warm ⇒ warm_access_cost
| MonadVM.Support.Variants.AccessStatus.Cold ⇒ cold_account_access_cost
end.
Definition _rocq_fallback_memory_cost_0 :
ltac:(let typ := constr:(ltac:(first [unshelve refine ((t → t)%type
)]; first [match goal with |- ?g ⇒ let sort := type of g in lazymatch sort with Set ⇒ fail | _ ⇒ shelve end end | eassumption | typeclasses eauto | RocqOfOCaml.Opaque.opaque_inhabit 64%nat])) in let typ := _rocq_witness_type typ in exact typ).
Proof. unshelve (RocqOfOCaml.Opaque.opaque_inhabit 64%nat). all: RocqOfOCaml.Opaque.opaque_inhabit 64%nat. Qed.
Definition memory_cost (revision : MonadVM.Chain.Monad.Revision.active)
: MonadVM.Support.UintN.t → MonadVM.Support.UintN.t :=
match revision with
| MonadVM.Support.Variants.Revision.Eight ⇒
let memory_cost_per_word := op_tildedollar 3 in
fun (active_memory_words : MonadVM.Support.UintN.t) ⇒
MonadVM.Support.UintN.op_plus
(MonadVM.Support.UintN.op_div
(MonadVM.Support.UintN.op_starstar active_memory_words 2)
(MonadVM.Support.UintN.op_tildedollar 512))
(MonadVM.Support.UintN.op_star memory_cost_per_word active_memory_words)
|
(MonadVM.Support.Variants.Revision.Nine |
MonadVM.Support.Variants.Revision.Eleven) ⇒
fun (active_memory_words : MonadVM.Support.UintN.t) ⇒
MonadVM.Support.UintN.op_div active_memory_words
(MonadVM.Support.UintN.op_tildedollar 2)
| _ ⇒ _rocq_fallback_memory_cost_0
end.
Definition copy_cost_per_word : MonadVM.Support.UintN.t := op_tildedollar 3.
Definition block_hash_cost : MonadVM.Support.UintN.t := op_tildedollar 20.
Definition sset_cost : MonadVM.Support.UintN.t := op_tildedollar 20000.
Definition sclear_refund : MonadVM.Support.UintN.t := op_tildedollar 4800.
Definition sreset_cost : MonadVM.Support.UintN.t := op_tildedollar 2900.
Definition create_cost : MonadVM.Support.UintN.t := op_tildedollar 32000.
Definition create_cost_per_initcode_word : MonadVM.Support.UintN.t :=
op_tildedollar 2.
Definition code_deposit_per_byte : MonadVM.Support.UintN.t :=
op_tildedollar 200.
Definition c_gascap
(gas : MonadVM.Support.UintN.Impl.t) (gas_left : MonadVM.Support.UintN.Impl.t)
(memory_cost : MonadVM.Support.UintN.t) (extra_cost : MonadVM.Support.UintN.t)
: MonadVM.Support.UintN.Impl.t :=
if
MonadVM.Support.UintN.op_gteq gas_left
(MonadVM.Support.UintN.op_plus memory_cost extra_cost)
then
let available_gas :=
MonadVM.Support.UintN.op_minus
(MonadVM.Support.UintN.op_minus gas_left memory_cost) extra_cost in
MonadVM.Support.UintN.min gas
(MonadVM.Support.UintN.minus_1_64th available_gas)
else
gas.
Module call_gas.
Record record : Set := Build {
caller_spent_gas : MonadVM.Support.UintN.t;
callee_available_gas : MonadVM.Support.UintN.t;
}.
Definition with_caller_spent_gas caller_spent_gas (r : record) :=
Build caller_spent_gas r.(callee_available_gas).
Definition with_callee_available_gas callee_available_gas (r : record) :=
Build r.(caller_spent_gas) callee_available_gas.
End call_gas.
Definition call_gas := call_gas.record.
op_tildedollar 30000000.
Definition jumpdest : MonadVM.Support.UintN.t := op_tildedollar 1.
Definition base : MonadVM.Support.UintN.t := op_tildedollar 2.
Definition very_low : MonadVM.Support.UintN.t := op_tildedollar 3.
Definition low : MonadVM.Support.UintN.t := op_tildedollar 5.
Definition mid : MonadVM.Support.UintN.t := op_tildedollar 8.
Definition high : MonadVM.Support.UintN.t := op_tildedollar 10.
Definition exp_base_cost : MonadVM.Support.UintN.t := op_tildedollar 10.
Definition exp_cost_per_byte : MonadVM.Support.UintN.t := op_tildedollar 50.
Definition keccak256_base_cost : MonadVM.Support.UintN.t := op_tildedollar 30.
Definition keccak256_cost_per_word : MonadVM.Support.UintN.t :=
op_tildedollar 6.
Definition log_cost : MonadVM.Support.UintN.t := op_tildedollar 375.
Definition log_cost_per_byte : MonadVM.Support.UintN.t := op_tildedollar 8.
Definition log_cost_per_topic : MonadVM.Support.UintN.t := op_tildedollar 375.
Definition self_destruct_cost : MonadVM.Support.UintN.t := op_tildedollar 5000.
Definition self_destruct_new_account_cost : MonadVM.Support.UintN.t :=
op_tildedollar 25000.
Definition new_account_cost : MonadVM.Support.UintN.t := op_tildedollar 25000.
Definition call_value : MonadVM.Support.UintN.t := op_tildedollar 9000.
Definition call_stipend : MonadVM.Support.UintN.t := op_tildedollar 2300.
Definition cold_sload_cost : MonadVM.Support.UintN.t := op_tildedollar 8100.
Definition cold_account_access_cost : MonadVM.Support.UintN.t :=
op_tildedollar 10100.
Definition warm_access_cost : MonadVM.Support.UintN.t := op_tildedollar 100.
Definition account_access_cost
(function_parameter : MonadVM.Support.Variants.AccessStatus.t)
: MonadVM.Support.UintN.t :=
match function_parameter with
| MonadVM.Support.Variants.AccessStatus.Warm ⇒ warm_access_cost
| MonadVM.Support.Variants.AccessStatus.Cold ⇒ cold_account_access_cost
end.
Definition _rocq_fallback_memory_cost_0 :
ltac:(let typ := constr:(ltac:(first [unshelve refine ((t → t)%type
)]; first [match goal with |- ?g ⇒ let sort := type of g in lazymatch sort with Set ⇒ fail | _ ⇒ shelve end end | eassumption | typeclasses eauto | RocqOfOCaml.Opaque.opaque_inhabit 64%nat])) in let typ := _rocq_witness_type typ in exact typ).
Proof. unshelve (RocqOfOCaml.Opaque.opaque_inhabit 64%nat). all: RocqOfOCaml.Opaque.opaque_inhabit 64%nat. Qed.
Definition memory_cost (revision : MonadVM.Chain.Monad.Revision.active)
: MonadVM.Support.UintN.t → MonadVM.Support.UintN.t :=
match revision with
| MonadVM.Support.Variants.Revision.Eight ⇒
let memory_cost_per_word := op_tildedollar 3 in
fun (active_memory_words : MonadVM.Support.UintN.t) ⇒
MonadVM.Support.UintN.op_plus
(MonadVM.Support.UintN.op_div
(MonadVM.Support.UintN.op_starstar active_memory_words 2)
(MonadVM.Support.UintN.op_tildedollar 512))
(MonadVM.Support.UintN.op_star memory_cost_per_word active_memory_words)
|
(MonadVM.Support.Variants.Revision.Nine |
MonadVM.Support.Variants.Revision.Eleven) ⇒
fun (active_memory_words : MonadVM.Support.UintN.t) ⇒
MonadVM.Support.UintN.op_div active_memory_words
(MonadVM.Support.UintN.op_tildedollar 2)
| _ ⇒ _rocq_fallback_memory_cost_0
end.
Definition copy_cost_per_word : MonadVM.Support.UintN.t := op_tildedollar 3.
Definition block_hash_cost : MonadVM.Support.UintN.t := op_tildedollar 20.
Definition sset_cost : MonadVM.Support.UintN.t := op_tildedollar 20000.
Definition sclear_refund : MonadVM.Support.UintN.t := op_tildedollar 4800.
Definition sreset_cost : MonadVM.Support.UintN.t := op_tildedollar 2900.
Definition create_cost : MonadVM.Support.UintN.t := op_tildedollar 32000.
Definition create_cost_per_initcode_word : MonadVM.Support.UintN.t :=
op_tildedollar 2.
Definition code_deposit_per_byte : MonadVM.Support.UintN.t :=
op_tildedollar 200.
Definition c_gascap
(gas : MonadVM.Support.UintN.Impl.t) (gas_left : MonadVM.Support.UintN.Impl.t)
(memory_cost : MonadVM.Support.UintN.t) (extra_cost : MonadVM.Support.UintN.t)
: MonadVM.Support.UintN.Impl.t :=
if
MonadVM.Support.UintN.op_gteq gas_left
(MonadVM.Support.UintN.op_plus memory_cost extra_cost)
then
let available_gas :=
MonadVM.Support.UintN.op_minus
(MonadVM.Support.UintN.op_minus gas_left memory_cost) extra_cost in
MonadVM.Support.UintN.min gas
(MonadVM.Support.UintN.minus_1_64th available_gas)
else
gas.
Module call_gas.
Record record : Set := Build {
caller_spent_gas : MonadVM.Support.UintN.t;
callee_available_gas : MonadVM.Support.UintN.t;
}.
Definition with_caller_spent_gas caller_spent_gas (r : record) :=
Build caller_spent_gas r.(callee_available_gas).
Definition with_callee_available_gas callee_available_gas (r : record) :=
Build r.(caller_spent_gas) callee_available_gas.
End call_gas.
Definition call_gas := call_gas.record.
Before a call instruction, call_gas computes the gas that will be spent by the caller (excluding the
cost of memory expansion, which is paid separately) and the gas that will be available for the callee.
Definition call_gas_value
(transfer_value : bool) (gas : MonadVM.Support.UintN.Impl.t)
(gas_left : MonadVM.Support.UintN.Impl.t)
(memory_cost : MonadVM.Support.UintN.t) (extra_cost : MonadVM.Support.UintN.t)
: call_gas :=
let c_gascap := c_gascap gas gas_left memory_cost extra_cost in
let caller_spent_gas := MonadVM.Support.UintN.op_plus c_gascap extra_cost in
let callee_available_gas :=
if transfer_value then
MonadVM.Support.UintN.op_plus c_gascap call_stipend
else
c_gascap in
{| MonadVM.Gas.call_gas.caller_spent_gas := caller_spent_gas;
MonadVM.Gas.call_gas.callee_available_gas := callee_available_gas; |}.
(transfer_value : bool) (gas : MonadVM.Support.UintN.Impl.t)
(gas_left : MonadVM.Support.UintN.Impl.t)
(memory_cost : MonadVM.Support.UintN.t) (extra_cost : MonadVM.Support.UintN.t)
: call_gas :=
let c_gascap := c_gascap gas gas_left memory_cost extra_cost in
let caller_spent_gas := MonadVM.Support.UintN.op_plus c_gascap extra_cost in
let callee_available_gas :=
if transfer_value then
MonadVM.Support.UintN.op_plus c_gascap call_stipend
else
c_gascap in
{| MonadVM.Gas.call_gas.caller_spent_gas := caller_spent_gas;
MonadVM.Gas.call_gas.callee_available_gas := callee_available_gas; |}.