Library QedkConcrete.fixedprecompileoutputs

Fixed-size pairing and KZG responses

Cryptographic validation decides success, not the response size. Follow the native wrapper to its serializer without assuming that validation is correct or that the supplied points represent valid group elements.
From Stdlib Require Import ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Precompiles QedkConcrete.precompileoutputs QedkConcrete.bytewords.
Set Default Goal Selector "!".
Local Open Scope Z_scope.

Lemma alt_pairing_output_bounded
  {fallback : ltac:(let T := type of @Precompiles.Alt_bn128.pairing_check in
    lazymatch T with ?A → _ ⇒ exact A end)}
    (msg : Evmc.Message.t) :
  OCamlString.length (Evmc.Result.t.output_data
    (@Precompiles.Alt_bn128.pairing_check fallback msg)) ≤ 32.
Proof.
  unfold Precompiles.Alt_bn128.pairing_check. apply native_run_output; [lia|].
  repeat match goal with
  | |- nativeOutputBound _ (PC.op_letdollar _ _) ⇒
    apply native_output_bind; intro; cbn beta iota zeta
  end.
  apply native_output_return.
  apply Z.eq_le_incl. apply word_encoding_length.
Qed.

Lemma bls_pairing_output_bounded
  {fallback : ltac:(let T := type of @Precompiles.Bls12_381.pairing_check in
    lazymatch T with ?A → _ ⇒ exact A end)}
    (msg : Evmc.Message.t) :
  OCamlString.length (Evmc.Result.t.output_data
    (@Precompiles.Bls12_381.pairing_check fallback msg)) ≤ 32.
Proof.
  unfold Precompiles.Bls12_381.pairing_check. apply native_run_output; [lia|].
  repeat match goal with
  | |- nativeOutputBound _ (PC.op_letdollar _ _) ⇒
    apply native_output_bind; intro; cbn beta iota zeta
  end.
  apply native_output_return.
  match goal with |- context [if ?test then _ else _] ⇒ destruct test end;
    rewrite word_bytes_encoding_length; lia.
Qed.

Lemma kzg_output_bounded
      (msg : Evmc.Message.t) :
  OCamlString.length (Evmc.Result.t.output_data
    (@Precompiles.Point_evaluation.precompile msg)) ≤ 64.
Proof.
  unfold Precompiles.Point_evaluation.precompile. apply native_run_output; [lia|].
  repeat match goal with
  | |- nativeOutputBound _ (PC.op_letdollar _ _) ⇒
    apply native_output_bind; intro; cbn beta iota zeta
  end.
  apply native_output_return.
  unfold Precompiles.Point_evaluation.precompile_result.
  rewrite byte_append_length, !word_bytes_encoding_length. lia.
Qed.

Print Assumptions alt_pairing_output_bounded.
Print Assumptions bls_pairing_output_bounded.
Print Assumptions kzg_output_bounded.