ParserNumericDecimalOverflowCertificate

Lean checked

Statement

This explanation was written alongside the formalization to describe the statement and its reasoning.

Helper · Exact decimal-sequence overflow

Let first consist of eleven ASCII zero bytes, followed by the 19-byte word 1000000000000000080, followed by 2{,}147{,}483{,}618 ASCII zero bytes, and let body consist of 0. followed by first. The extracted parse_decimal_seq call on body fails with integerOverflow.

Lean statement

Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.

import Tablet.ParserNumericDecimalScalarCertificate
import Tablet.ParserNumericDecimalBulkCertificate
import Tablet.ParserNumericLeadingZeroCertificate
import Tablet.ParserNumericElevenZeroCertificate

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 262144

namespace dec2flt_model

-- [TABLET NODE: ParserNumericDecimalOverflowCertificate]
theorem ParserNumericDecimalOverflowCertificate (body first : Slice Std.U8)
    (hfirst : first.val = List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
      List.replicate 2147483618 48#u8)
    (hbody : body.val = [48#u8, 46#u8] ++ first.val) :
    num.imp.dec2flt.decimal_seq.parse_decimal_seq body =
      fail integerOverflow := by
Proof

Natural-language proof

The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.

Explanatory prose status

Prose retained as authored. The explanatory prose is preserved as it stood when captured.

Proof

The fixed concatenation has length 2^{31}. By ParserNumericLeadingZeroCertificate, the leading-zero loop leaves the point-prefixed slice. The first digit scan sees the point and therefore leaves the default, zero-digit decimal record unchanged. Dropping the point recovers first. By ParserNumericElevenZeroCertificate, the second zero loop removes exactly the eleven leading zeros, leaving the byte 1, the remaining 18 bytes of the displayed word, and the replicated zeros. Every remaining byte is an ASCII digit, and this residual has length 2{,}147{,}483{,}637.
Apply ParserNumericDecimalBulkCertificate at digit index zero. It returns an all-digit residual and preserves index plus residual length, with the index at most 767. Consequently the index plus residual length is below the 64-bit usize maximum fixed by Assumptions. Applying ParserNumericDecimalScalarCertificate then consumes the entire residual. Thus the final slice has length zero, while the slice immediately after the decimal point has length 2^{31}.
The extracted unsigned-to-signed 32-bit cast truncates these two lengths to 0 and -2^{31}, respectively; this follows directly from its zero-extension bit-vector definition at width 32. The decimal parser next performs the checked subtraction 0-(-2^{31})=2^{31}, which lies one above the signed 32-bit maximum. The extracted checked subtraction therefore returns integerOverflow, and monadic binding propagates that failure as the result of parse_decimal_seq.

Lean proof


  have hfirstLen : first.val.length = 2147483648 := by
    rw [hfirst]
    simp only [List.length_append, List.length_replicate, List.length_cons,
      List.length_nil]
  obtain ⟨point, hpoint, hleading⟩ :=
    ParserNumericLeadingZeroCertificate body first hbody
  have hpointBound : (46#u8 :: first.val).length <= Usize.max := by
    have hp := point.property
    rw [hpoint] at hp
    exact hp
  let point0 : Slice Std.U8 := ⟨46#u8 :: first.val, hpointBound⟩
  have hpointEq : point = point0 := (Slice.eq_iff _ _).2 (by
    simpa [point0] using hpoint)
  subst point
  let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq := {
    num_digits := 0#usize
    decimal_point := 0#i32
    truncated := false
    digits := Array.repeat 768#usize 0#u8
  }
  have hdefault :
      num.imp.dec2flt.decimal_seq.DecimalSeq.Insts.CoreDefaultDefault.default =
        ok d0 := by rfl
  have hpointScan :
      num.imp.dec2flt.decimal_seq.parse_digits_into_seq point0 d0 =
        ok (point0, d0) := by
    unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq
    unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop.body,
      point0, d0, Slice.index_usize, core.num.U8.wrapping_sub,
      Aeneas.Std.lift, U8.size_eq,
      core.slice.index.SliceIndexRangeFromUsizeSlice.index,
      Slice.drop, Slice.length]
  have hafterPoint :
      core.slice.index.SliceIndexRangeFromUsizeSlice.index
        { start := 1#usize } point0 = ok first := by
    simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
      Slice.drop, Slice.length, point0]
  let sigTail : List Std.U8 :=
    [48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
      48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
      48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
    List.replicate 2147483618 48#u8
  have hfirstTail : first.val =
      List.replicate 11 48#u8 ++ 49#u8 :: sigTail := by
    rw [hfirst]
    rfl
  obtain ⟨significant, hsignificant, hzeros⟩ :=
    ParserNumericElevenZeroCertificate first sigTail hfirstTail
  have hsigDigits : forall b, List.Mem b significant.val ->
      48 <= b.val /\ b.val <= 57 := by
    intro b hb
    rw [hsignificant] at hb
    rcases List.mem_cons.mp hb with rfl | hb
    · norm_num
    rcases List.mem_append.mp hb with hb | hb
    · simp only [List.mem_cons, List.not_mem_nil, or_false] at hb
      rcases hb with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl |
        rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
        norm_num
    · rw [List.mem_replicate] at hb
      rcases hb with ⟨_, rfl⟩
      norm_num
  have hsigLen : significant.val.length = 2147483637 := by
    have hpartition : first.val =
        List.replicate 11 48#u8 ++ significant.val := by
      rw [hfirstTail, hsignificant]
    have hlen := congrArg List.length hpartition
    simp only [List.length_append, List.length_replicate] at hlen
    omega
  obtain ⟨afterBulk, bulkCount, bulkArray, hbulk, hbulkDigits,
      hbulkCount, hconserve⟩ :=
    ParserNumericDecimalBulkCertificate significant 0#usize d0.digits
      hsigDigits (by norm_num)
  let preScalar : num.imp.dec2flt.decimal_seq.DecimalSeq :=
    { d0 with num_digits := bulkCount, digits := bulkArray }
  have hscalarBound :
      preScalar.num_digits.val + afterBulk.val.length <= UScalar.max .Usize := by
    simp [preScalar]
    rw [hconserve, hsigLen]
    have hbits := Dec2Flt.configured_x86_64_numBits
    simp [UScalar.max, hbits]
  obtain ⟨empty, d2, hscalar, hempty, hd2Count⟩ :=
    ParserNumericDecimalScalarCertificate afterBulk preScalar hbulkDigits
      hscalarBound
  have hcastEmpty : UScalar.hcast .I32 (Slice.len empty) = 0#i32 := by
    have hlen : Slice.len empty = 0#usize := by
      apply UScalar.eq_of_val_eq
      simpa [Slice.len_val] using congrArg List.length hempty
    rw [hlen]
    rw [IScalar.eq_equiv_bv_eq]
    apply BitVec.eq_of_toNat_eq
    simp only [UScalar.hcast, BitVec.zeroExtend_eq_setWidth,
      BitVec.toNat_setWidth, UScalar.bv_toNat, I32.ofInt_bv,
      BitVec.toNat_ofInt]
    norm_num
  have hcastFirst : UScalar.hcast .I32 (Slice.len first) =
      (-2147483648)#i32 := by
    have hlen : Slice.len first = 2147483648#usize := by
      apply UScalar.eq_of_val_eq
      simpa [Slice.len_val] using hfirstLen
    rw [hlen]
    rw [IScalar.eq_equiv_bv_eq]
    apply BitVec.eq_of_toNat_eq
    simp only [UScalar.hcast, BitVec.zeroExtend_eq_setWidth,
      BitVec.toNat_setWidth, UScalar.bv_toNat, I32.ofInt_bv,
      BitVec.toNat_ofInt]
    norm_num
    rfl
  have hsub : ((0#i32 : Std.I32) - (-2147483648)#i32) =
      fail integerOverflow := by
    rfl
  unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq
  simp [hdefault, hleading, hpointScan]
  simp [point0, Slice.index_usize, hafterPoint, d0, hzeros, hbulk,
    preScalar, hscalar, hcastEmpty, hcastFirst, Aeneas.Std.lift, hsub]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.ParserNumericDecimalScalarCertificate
import Tablet.ParserNumericDecimalBulkCertificate
import Tablet.ParserNumericLeadingZeroCertificate
import Tablet.ParserNumericElevenZeroCertificate

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000
set_option maxRecDepth 262144

namespace dec2flt_model

-- [TABLET NODE: ParserNumericDecimalOverflowCertificate]
theorem ParserNumericDecimalOverflowCertificate (body first : Slice Std.U8)
    (hfirst : first.val = List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
      List.replicate 2147483618 48#u8)
    (hbody : body.val = [48#u8, 46#u8] ++ first.val) :
    num.imp.dec2flt.decimal_seq.parse_decimal_seq body =
      fail integerOverflow := by
-- BODY
  have hfirstLen : first.val.length = 2147483648 := by
    rw [hfirst]
    simp only [List.length_append, List.length_replicate, List.length_cons,
      List.length_nil]
  obtain ⟨point, hpoint, hleading⟩ :=
    ParserNumericLeadingZeroCertificate body first hbody
  have hpointBound : (46#u8 :: first.val).length <= Usize.max := by
    have hp := point.property
    rw [hpoint] at hp
    exact hp
  let point0 : Slice Std.U8 := ⟨46#u8 :: first.val, hpointBound⟩
  have hpointEq : point = point0 := (Slice.eq_iff _ _).2 (by
    simpa [point0] using hpoint)
  subst point
  let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq := {
    num_digits := 0#usize
    decimal_point := 0#i32
    truncated := false
    digits := Array.repeat 768#usize 0#u8
  }
  have hdefault :
      num.imp.dec2flt.decimal_seq.DecimalSeq.Insts.CoreDefaultDefault.default =
        ok d0 := by rfl
  have hpointScan :
      num.imp.dec2flt.decimal_seq.parse_digits_into_seq point0 d0 =
        ok (point0, d0) := by
    unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq
    unfold num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop
    rw [Aeneas.Std.loop.eq_1]
    simp [num.imp.dec2flt.decimal_seq.parse_digits_into_seq_loop.body,
      point0, d0, Slice.index_usize, core.num.U8.wrapping_sub,
      Aeneas.Std.lift, U8.size_eq,
      core.slice.index.SliceIndexRangeFromUsizeSlice.index,
      Slice.drop, Slice.length]
  have hafterPoint :
      core.slice.index.SliceIndexRangeFromUsizeSlice.index
        { start := 1#usize } point0 = ok first := by
    simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
      Slice.drop, Slice.length, point0]
  let sigTail : List Std.U8 :=
    [48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
      48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
      48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
    List.replicate 2147483618 48#u8
  have hfirstTail : first.val =
      List.replicate 11 48#u8 ++ 49#u8 :: sigTail := by
    rw [hfirst]
    rfl
  obtain ⟨significant, hsignificant, hzeros⟩ :=
    ParserNumericElevenZeroCertificate first sigTail hfirstTail
  have hsigDigits : forall b, List.Mem b significant.val ->
      48 <= b.val /\ b.val <= 57 := by
    intro b hb
    rw [hsignificant] at hb
    rcases List.mem_cons.mp hb with rfl | hb
    · norm_num
    rcases List.mem_append.mp hb with hb | hb
    · simp only [List.mem_cons, List.not_mem_nil, or_false] at hb
      rcases hb with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl |
        rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;>
        norm_num
    · rw [List.mem_replicate] at hb
      rcases hb with ⟨_, rfl⟩
      norm_num
  have hsigLen : significant.val.length = 2147483637 := by
    have hpartition : first.val =
        List.replicate 11 48#u8 ++ significant.val := by
      rw [hfirstTail, hsignificant]
    have hlen := congrArg List.length hpartition
    simp only [List.length_append, List.length_replicate] at hlen
    omega
  obtain ⟨afterBulk, bulkCount, bulkArray, hbulk, hbulkDigits,
      hbulkCount, hconserve⟩ :=
    ParserNumericDecimalBulkCertificate significant 0#usize d0.digits
      hsigDigits (by norm_num)
  let preScalar : num.imp.dec2flt.decimal_seq.DecimalSeq :=
    { d0 with num_digits := bulkCount, digits := bulkArray }
  have hscalarBound :
      preScalar.num_digits.val + afterBulk.val.length <= UScalar.max .Usize := by
    simp [preScalar]
    rw [hconserve, hsigLen]
    have hbits := Dec2Flt.configured_x86_64_numBits
    simp [UScalar.max, hbits]
  obtain ⟨empty, d2, hscalar, hempty, hd2Count⟩ :=
    ParserNumericDecimalScalarCertificate afterBulk preScalar hbulkDigits
      hscalarBound
  have hcastEmpty : UScalar.hcast .I32 (Slice.len empty) = 0#i32 := by
    have hlen : Slice.len empty = 0#usize := by
      apply UScalar.eq_of_val_eq
      simpa [Slice.len_val] using congrArg List.length hempty
    rw [hlen]
    rw [IScalar.eq_equiv_bv_eq]
    apply BitVec.eq_of_toNat_eq
    simp only [UScalar.hcast, BitVec.zeroExtend_eq_setWidth,
      BitVec.toNat_setWidth, UScalar.bv_toNat, I32.ofInt_bv,
      BitVec.toNat_ofInt]
    norm_num
  have hcastFirst : UScalar.hcast .I32 (Slice.len first) =
      (-2147483648)#i32 := by
    have hlen : Slice.len first = 2147483648#usize := by
      apply UScalar.eq_of_val_eq
      simpa [Slice.len_val] using hfirstLen
    rw [hlen]
    rw [IScalar.eq_equiv_bv_eq]
    apply BitVec.eq_of_toNat_eq
    simp only [UScalar.hcast, BitVec.zeroExtend_eq_setWidth,
      BitVec.toNat_setWidth, UScalar.bv_toNat, I32.ofInt_bv,
      BitVec.toNat_ofInt]
    norm_num
    rfl
  have hsub : ((0#i32 : Std.I32) - (-2147483648)#i32) =
      fail integerOverflow := by
    rfl
  unfold num.imp.dec2flt.decimal_seq.parse_decimal_seq
  simp [hdefault, hleading, hpointScan]
  simp [point0, Slice.index_usize, hafterPoint, d0, hzeros, hbulk,
    preScalar, hscalar, hcastEmpty, hcastFirst, Aeneas.Std.lift, hsub]

end dec2flt_model

Proof structure

Follow the declared dependencies to read the supporting statements and proofs.

Explore this dependency tree

Inspect related source (77)
More program dependencies (44)
Standard-library dependencies (30)

Related source and models come from the extraction records and declared dependencies.

Proof assumptions and review

Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.

Transitive assumptions

This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.

Helper theorems included
All 21 entries
Technical checking records
Local closure summary
{
  "node": "ParserNumericDecimalOverflowCertificate",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "c6e0e572ae137ca8a437af959da576edde98e59e29a482325dd2957ab58b93aa",
  "active_statement_hash": "bef6f381a5548558ab012ea8bfe30c27369bc97770966657542c8dc8b17ee172",
  "kernel_axioms": [
    "Classical.choice",
    "Dec2Flt.configured_x86_64_numBits",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-126",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "ParserNumericDecimalBulkCertificate": "66ebef5d78cc28bd",
    "ParserNumericDecimalScalarCertificate": "0a344106deb781da",
    "ParserNumericElevenZeroCertificate": "9bf87361533b18e9",
    "ParserNumericLeadingZeroCertificate": "7012923e42a351b9",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "854af4cc12136a58",
    "num_imp_dec2flt_decimal_seq_parse_digits_into_seq": "bcad6df678c024ae"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "6799fe6525ddb761",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_Insts_CoreDefaultDefault_default": "7b9921904495bc2a",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS_WITHOUT_OVERFLOW": "65634ac95536dcca",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_try_add_digit": "69a4869a11307175",
    "num_imp_dec2flt_decimal_seq_count_trailing_zeros": "7a77bc9e01c1a09b",
    "num_imp_dec2flt_decimal_seq_parse_decimal_exponent": "e22eec67a6a49ff8",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "66dce2c574224f01",
    "num_imp_dec2flt_decimal_seq_parse_digits_into_seq": "7dd64a9afcbab98c"
  }
}
Prose assessment
{
  "label": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:093f04ccf19e4fe5856fe35ab3262fc0db9bde7f67c026b864793538695f0b4f",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}