Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universe overflow causes Russell's paradox #5706

Closed
Trebor-Huang opened this issue Dec 22, 2021 · 7 comments · Fixed by #5707
Closed

Universe overflow causes Russell's paradox #5706

Trebor-Huang opened this issue Dec 22, 2021 · 7 comments · Fixed by #5707
Assignees
Labels
false Proof of the empty type which checks without known-unsafe flags (e.g. without --type-in-type) levels regression in 2.6.2 Regression that first appeared in Agda 2.6.2 type: bug Issues and pull requests about actual bugs
Milestone

Comments

@Trebor-Huang
Copy link

Trebor-Huang commented Dec 22, 2021

Version used: Agda 2.6.2.1

{-# OPTIONS --safe #-}
module set-in-set where
-- Basically just a modified version of http://liamoc.net/posts/2015-09-10-girards-paradox.html
-- Some preliminaries, just to avoid any library imports
data _≡_ {ℓ : _} {A : Set ℓ} : A -> A -> Set where
    refl :  {a} -> a ≡ a

record Σ (A : Set) (P : A -> Set) : Set where
    constructor _,_
    field
        proj₁ : A
        proj₂ : P proj₁
open Σ

data  : Set where

-- This shows the problem
WTF : Set₀
WTF = Set₁₈₄₄₆₇₄₄₀₇₃₇₀₉₅₅₁₆₁₅
-- 18446744073709551615 = 2^64 - 1

-- The following is basically copying from the link
data SET : Set where
  set : (X : Set₁₈₄₄₆₇₄₄₀₇₃₇₀₉₅₅₁₆₁₅)  (X  SET)  SET

_∈_ : SET  SET  Set
a ∈ set X f = Σ X (λ x  a ≡ f x)

_∉_ : SET  SET  Set
a ∉ b = (a ∈ b) Δ : SET
Δ = set (Σ SET (λ s  s ∉ s)) proj₁

x∈Δ→x∉x :  {X}  X ∈ Δ  X ∉ X
x∈Δ→x∉x ((Y , Y∉Y) , refl) = Y∉Y

Δ∉Δ : Δ ∉ Δ
Δ∉Δ Δ∈Δ = x∈Δ→x∉x Δ∈Δ Δ∈Δ

x∉x→x∈Δ :  {X}   X ∉ X  X ∈ Δ
x∉x→x∈Δ {X} X∉X = (X , X∉X) , refl

falso : ⊥
falso = Δ∉Δ (x∉x→x∈Δ Δ∉Δ)
@Trebor-Huang
Copy link
Author

Discovered by @ksqsf . See the adjacent issue about __IMPOSSIBLE__ errors on subscript formatting.

@gallais gallais added false Proof of the empty type which checks without known-unsafe flags (e.g. without --type-in-type) levels type: bug Issues and pull requests about actual bugs labels Dec 22, 2021
@gallais gallais added this to the 2.6.3 milestone Dec 22, 2021
@gallais gallais assigned gallais and unassigned gallais Dec 22, 2021
@andreasabel andreasabel self-assigned this Dec 22, 2021
@Trebor-Huang
Copy link
Author

Correction: The error occurs at 2^63.

  • At l > 2^63-1, Set_l : Set0 (I'm using pseudo-notation) is accepted, no matter what l is.
  • At l = 2^63-1, __IMPOSSIBLE__ occurs.
  • At lower levels, Agda correctly rejects the declaration.

@andreasabel andreasabel added the regression in 2.6.2 Regression that first appeared in Agda 2.6.2 label Dec 22, 2021
@andreasabel
Copy link
Member

Curious what introduced this bug:

$ agda-bisect --must-fail --with-compiler ghc-8.8.4 --with-cabal cabal-3.2 --good v2.6.1 --bad v2.6.2 Issue5706.agda 

@Trebor-Huang
Copy link
Author

@AliasQli identified that if you change these Ints into Integers then Agda correctly rejects the file.

data Suffix
= Prime Int -- ^ Identifier ends in @Int@ many primes.
| Index Int -- ^ Identifier ends in number @Int@ (ordinary digits).
| Subscript Int -- ^ Identifier ends in number @Int@ (subscript digits).

But those were written ages ago.

@andreasabel
Copy link
Member

Yes, this is the easiest fix, I am working on a PR. However, I am still curious what causes the regression, and once I have seen the cause, I have more information to decide on a fix.

@andreasabel andreasabel changed the title Universe overflow causes Girard's paradox Universe overflow causes Russell's paradox Dec 22, 2021
@andreasabel
Copy link
Member

bisect says: 55013a9 is the first bad commit
Date: Mon Oct 19 17:35:36 2020 +0200

[ refactor ] smart constructor [s]sort should use smart univSort

Otherwise, non-normal sorts like (UnivSort (SSet l)) are created.

Unfortunately, that was me. 😊

But it is almost as if I fell into a trap that was laid out over time. So I suppose fixing Utils.Suffix to use Integer is the right way to go.

@gallais
Copy link
Member

gallais commented Dec 22, 2021

I suspect it may come from #4629. Prior to that we could directly parse the level n
in Setn. After that the decomposition into name + suffix can only be done after /
during scope checking and so we started repurposing Agda.Utils.Suffix only originally
used for name generation (when case splitting / shadowing).

andreasabel added a commit that referenced this issue Dec 22, 2021
`Int` suffixes could be exploited by overflow to get Set:Set in Agda
2.6.2(.1).  This is fixed by switching to `Integer` suffixes.
forked-from-1kasper added a commit to groupoid/anders that referenced this issue Dec 23, 2021
andreasabel added a commit that referenced this issue Dec 23, 2021
`Int` suffixes could be exploited by overflow to get Set:Set in Agda
2.6.2(.1).  This is fixed by switching to `Integer` suffixes.
@andreasabel andreasabel modified the milestones: 2.6.3, 2.6.2.2 Mar 14, 2022
@andreasabel andreasabel mentioned this issue Mar 14, 2022
41 tasks
andreasabel added a commit that referenced this issue Mar 15, 2022
`Int` suffixes could be exploited by overflow to get Set:Set in Agda
2.6.2(.1).  This is fixed by switching to `Integer` suffixes.
andreasabel added a commit that referenced this issue Mar 16, 2022
`Int` suffixes could be exploited by overflow to get Set:Set in Agda
2.6.2(.1).  This is fixed by switching to `Integer` suffixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false Proof of the empty type which checks without known-unsafe flags (e.g. without --type-in-type) levels regression in 2.6.2 Regression that first appeared in Agda 2.6.2 type: bug Issues and pull requests about actual bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants