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

[Parameterized Modules] Variable Substitution Crash #796

Closed
WeeknightMVP opened this issue Jul 2, 2020 · 1 comment · Fixed by #959
Closed

[Parameterized Modules] Variable Substitution Crash #796

WeeknightMVP opened this issue Jul 2, 2020 · 1 comment · Fixed by #959
Assignees
Labels
bug Something not working correctly parameterized modules Related to Cryptol's parameterized modules

Comments

@WeeknightMVP
Copy link

BlockCipher.cry:

module BlockCipher where

parameter
  type Key: *
  type Block: *

  encrypt_block: Key -> Block -> Block

Kaboom.cry:

module Kaboom = BlockCipher where

parameter
  type _k: #

type Key = [8 * _k]
type Block = [64]
type RoundKey = [64]

aux : RoundKey -> Block -> Block
aux RK P = zero

// key_schedule : Key -> RoundKey
key_schedule K = zero
  where
    _ = [ groupBy`{4} K ]

// encrypt_block : Key -> Block -> Block
encrypt_block key pt = aux (key_schedule key) pt
> chcp 65001
Active code page: 65001
> cryptol
┏━╸┏━┓╻ ╻┏━┓╺┳╸┏━┓╻
┃  ┣┳┛┗┳┛┣━┛ ┃ ┃ ┃┃
┗━╸╹┗╸ ╹ ╹   ╹ ┗━┛┗━╸
version 2.8.1 (1e1f7af, modified)
https://cryptol.net  :? for help

Loading module Cryptol
Cryptol> :m Kaboom
Loading module BlockCipher
Loading module Kaboom
cryptol: You have encountered a bug in Cryptol's implementation.
*** Please create an issue at https://github.com/GaloisInc/cryptol/issues

%< ---------------------------------------------------
  Revision:  1e1f7af812b122e0dcd4f4d36a2a84a4864427a4
  Branch:    HEAD (uncommited files present)
  Location:  Cryptol.TypeCheck.Monad.extendSubst
  Message:   Escaped quantified variables:
             Substitution:  ?Kaboom::encrypt_block_1`934 := 2 * Kaboom::_k
             Vars in scope: []
             Escaped:       [Kaboom::_k]
CallStack (from HasCallStack):
  panic, called at src\Cryptol\Utils\Panic.hs:21:9 in cryptol-2.8.1-CsLNPSw0BJM1P20gctBZPn:Cryptol.Utils.Panic
  panic, called at src\Cryptol\TypeCheck\Monad.hs:561:16 in cryptol-2.8.1-CsLNPSw0BJM1P20gctBZPn:Cryptol.TypeCheck.Monad
%< ---------------------------------------------------

Uncommenting either of the type signatures for key_schedule or encrypt_block avoids the crash. Commenting out where _ = [ groupBy`{4} K ] produces an error for insufficient polymorphism:

[error] at ...\Kaboom.cry:19:1--19:14:
  The type ?Kaboom::encrypt_block_1`949 is not sufficiently polymorphic.
    It cannot depend on quantified variables: _k
  where
  ?Kaboom::encrypt_block_1`949 is 1st type argument of 'encrypt_block' at ...\Kaboom.cry:19:1--19:14
  _k is module parameter _k at ...\Kaboom.cry:4:8--4:10
@yav
Copy link
Member

yav commented Jul 2, 2020

Thanks for reporting this. It looks like we forgot to add the module parameters as being in scope somewhere, probably when checking module instantiations.

@robdockins robdockins added bug Something not working correctly parameterized modules Related to Cryptol's parameterized modules labels Jul 2, 2020
@yav yav self-assigned this Nov 11, 2020
yav added a commit that referenced this issue Nov 11, 2020
This fixes #796.
It also fixes the @bboston7's example on #883, but not the original
example in #883.   The issue there is that `asdf` function generates
a constraint only involving the module parameter.

Normally we don't try to solve constraint that don't mention a schema's
parameters, because they can always be solved "later", and hopefully with
more things instantiated.

The weird thing in this case is that the schema adds *local" constraint to
the module parameters, but we end up ignoring these.
@yav yav closed this as completed in #959 Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something not working correctly parameterized modules Related to Cryptol's parameterized modules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants