Library SetcodeConcrete.nativeoutputs
Bounds for every native precompile in the SETCODE revision
From Stdlib Require Import ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.dispatchoutputs QedkConcrete.modexpoutputs
QedkConcrete.precompileoutputs QedkConcrete.blsmapbounds QedkConcrete.assemblychecked
QedkConcrete.hashwords QedkConcrete.hostchecked QedkConcrete.vmsupplywords
QedkConcrete.vmcallchecked QedkConcrete.recursiveassembly
SetcodeConcrete.executionsupply.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Lemma setcode_modexp_parameter_bound {MF : MX.FArgs} prices :
MF.(MX.Revision).(Precompiles.Modexp.Make_Revision_signature.revision) =
Support.Variants.Revision.Setcode prices →
nativeEnsures (fun n ⇒ (n ≤ 1024)%N) (@MX.parameter_length MF).
Proof.
intro Hrevision. unfold MX.parameter_length. rewrite Hrevision.
apply native_ensures_any; intro n.
change (nativeEnsures (fun n ⇒ (n ≤ 1024)%N)
(PC.op_letdollar (PC.when_ (N.ltb 1024 n) PC.precompile_failure)
(fun _ ⇒ PC._return n))).
destruct (N.ltb_spec 1024 n) as [Hlarge|Hsmall].
- intros state. exact I.
- apply native_ensures_any; intros []. apply native_ensures_return. lia.
Qed.
Theorem setcode_native_output_bounds {HF : Host.Instantiate.FArgs} prices :
HF.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) =
Support.Variants.Revision.Setcode prices →
sha256OutputSize → blsG1CofactorOrder → blsG2CofactorOrder →
@nativeOutputBounds HF.
Proof.
intros Hrevision Hsha H1 H2. apply native_output_bounds_from_table.
- intro vm. eapply setcode_reserve_precompile_table. exact Hrevision.
- intros MF Hrev. eapply setcode_modexp_parameter_bound. rewrite Hrev. exact Hrevision.
- exact Hsha.
- apply bls_map_output_bounds_from_cofactor_orders; assumption.
Qed.
Print Assumptions setcode_native_output_bounds.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.dispatchoutputs QedkConcrete.modexpoutputs
QedkConcrete.precompileoutputs QedkConcrete.blsmapbounds QedkConcrete.assemblychecked
QedkConcrete.hashwords QedkConcrete.hostchecked QedkConcrete.vmsupplywords
QedkConcrete.vmcallchecked QedkConcrete.recursiveassembly
SetcodeConcrete.executionsupply.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Lemma setcode_modexp_parameter_bound {MF : MX.FArgs} prices :
MF.(MX.Revision).(Precompiles.Modexp.Make_Revision_signature.revision) =
Support.Variants.Revision.Setcode prices →
nativeEnsures (fun n ⇒ (n ≤ 1024)%N) (@MX.parameter_length MF).
Proof.
intro Hrevision. unfold MX.parameter_length. rewrite Hrevision.
apply native_ensures_any; intro n.
change (nativeEnsures (fun n ⇒ (n ≤ 1024)%N)
(PC.op_letdollar (PC.when_ (N.ltb 1024 n) PC.precompile_failure)
(fun _ ⇒ PC._return n))).
destruct (N.ltb_spec 1024 n) as [Hlarge|Hsmall].
- intros state. exact I.
- apply native_ensures_any; intros []. apply native_ensures_return. lia.
Qed.
Theorem setcode_native_output_bounds {HF : Host.Instantiate.FArgs} prices :
HF.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) =
Support.Variants.Revision.Setcode prices →
sha256OutputSize → blsG1CofactorOrder → blsG2CofactorOrder →
@nativeOutputBounds HF.
Proof.
intros Hrevision Hsha H1 H2. apply native_output_bounds_from_table.
- intro vm. eapply setcode_reserve_precompile_table. exact Hrevision.
- intros MF Hrev. eapply setcode_modexp_parameter_bound. rewrite Hrev. exact Hrevision.
- exact Hsha.
- apply bls_map_output_bounds_from_cofactor_orders; assumption.
Qed.
Print Assumptions setcode_native_output_bounds.
No recursive-call or precompile-output premise remains. The two hash
contracts and BLS cofactor identities are the approved library premises.
Theorem concrete_transaction_call_supply {F : E.FArgs}
cold warm access write reserve limit tx msg initial :
E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
(0 < cold)%N → (0 < warm)%N →
keccak256OutputSize → sha256OutputSize →
blsG1CofactorOrder → blsG2CofactorOrder →
vmMessageBounds msg →
hostSupplyContext E.Instantiation_fargs.(Host.Instantiate.ChainParams) limit initial →
let result := E.Host.call_from_eoa tx msg initial in
hostSupplyContext E.Instantiation_fargs.(Host.Instantiate.ChainParams) limit (snd result) ∧
resultOutputBound (fst result).
Proof.
intros Hrevision Hcold Hwarm Hhash Hsha H1 H2 Hmsg Hinitial.
eapply execution_call_from_sender_supply; try eassumption.
eapply setcode_native_output_bounds; eassumption.
Qed.
Print Assumptions concrete_transaction_call_supply.
cold warm access write reserve limit tx msg initial :
E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
(0 < cold)%N → (0 < warm)%N →
keccak256OutputSize → sha256OutputSize →
blsG1CofactorOrder → blsG2CofactorOrder →
vmMessageBounds msg →
hostSupplyContext E.Instantiation_fargs.(Host.Instantiate.ChainParams) limit initial →
let result := E.Host.call_from_eoa tx msg initial in
hostSupplyContext E.Instantiation_fargs.(Host.Instantiate.ChainParams) limit (snd result) ∧
resultOutputBound (fst result).
Proof.
intros Hrevision Hcold Hwarm Hhash Hsha H1 H2 Hmsg Hinitial.
eapply execution_call_from_sender_supply; try eassumption.
eapply setcode_native_output_bounds; eassumption.
Qed.
Print Assumptions concrete_transaction_call_supply.