Init.ShareCommon unchecked StateFactoryBuilder breaks runtime/spec consistency
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 領域
- compilers
調査の方向性
Start with src/Init/ShareCommon.lean lines 47–86 and the minimal reproduction in the issue, then trace how StateFactoryBuilder callbacks are used by StateFactory.mk and State.shareCommon at runtime. Determine how to preserve the logical result when callbacks are non-lawful and verify that the reproduction no longer makes native_decide derive a contradiction.
索引モデルが issue の本文から書いたものです。
説明
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”) - When reporting a perceived soundness bug: Does it affect
lake check --paranoid?
Paranoid catches it
Description
ShareCommon.StateFactoryBuilder is a public structure with no lawfulness constraints on mapFind? / setFind?, and ShareCommon.StateFactory.mk is a public opaque function implemented via unsafeCast (@[implemented_by Internal.StateFactory.mkImpl]). Meanwhile, ShareCommon.State.shareCommon has the pure logical definition (a, s) while executing @[extern "lean_state_sharecommon"] at runtime, returning whatever setFind? / mapFind? returns.
Providing a non-lawful setFind? (e.g., returning the previously inserted element regardless of the lookup key) makes (s.shareCommon a).1 disagree with its logical definition a—and across distinct types α ≠ β, returns an α value at type β in safe Lean (no unsafe, @[extern], or @[implemented_by]). This breaks runtime type safety and lets native_decide prove 0 = 1.
Scope: Does not affect pure-kernel proofs (the proof of 0 = 1 depends on .native_decide.ax_ and is rejected by standard axiom checks). Still present on master after #16715.
Where issue is
src/Init/ShareCommon.lean lines 47–86 (e6e9431b15):
public structure StateFactoryBuilder (lines 47–55)
@[implemented_by Internal.StateFactory.mkImpl] public opaque StateFactory.mk (lines 71–72)
@[extern "lean_state_sharecommon"] public def State.shareCommon (lines 85–86)
Minimum Reproducible Issue
import Init.ShareCommon
def evilFactory : ShareCommon.StateFactory :=
ShareCommon.StateFactory.mk {
Map := fun _ β _ _ => Option β
mkMap := fun _ => none
mapFind? := fun m _ => m
mapInsert := fun _ _ v => some v
Set := fun α _ _ => Option α
mkSet := fun _ => none
setFind? := fun s _ => s
setInsert := fun _ x => some x
}
def evilVal : List Nat :=
let s0 : ShareCommon.State.{0} evilFactory := ShareCommon.State.mk evilFactory
let (_, s1) := s0.shareCommon [0]
(s1.shareCommon [1]).1
theorem evil_spec : evilVal = [1] := rfl
theorem evil_native : evilVal = [0] := by native_decide
theorem zero_eq_one : 0 = 1 := by
have h : ([0] : List Nat) = [1] := evil_native.symm.trans evil_spec
injection h
#print axioms zero_eq_one
Output
'zero_eq_one' depends on axioms: [Classical.choice, evil_native._native.native_decide.ax_1_1]
Versions
v4.36.0 , v4.37.0-rc1
- 主要言語
- Lean
- スター
- 10.3k
- フォーク
- 1.1k
- 平均マージ
- 16時間 45分
- マージ済み PR(30日)
- 361
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
leanprover/lean4 のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
leanprover/lean4#16876 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
leanprover/lean4#16842 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
leanprover/lean4#16841 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
leanprover/lean4#16840 ·
メンテナーはふだん 1 日以内に返信
-
doc: stray "public" in Bool and HEq documentation再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
leanprover/lean4#16825 ·
メンテナーはふだん 1 日以内に返信
leanprover/lean4 の issue をすべて見る
似ている issue
-
bug core-lang
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Call-argument syntax diagnostic needs example spacing and removal of confusing trailing sentenceオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
mw00/project-maya#1368 ·
メンテナーはふだん 2 日以内に返信
-
test(bind-json): legacy Solidity fixture requires an unavailable solc on Linux ARM64対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
foundry-rs/foundry#18828 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信