Chia-Network / clvm_tools

Tools for clvm development
Apache License 2.0
51 stars 32 forks source link

Compiler fails sometimes when parameter deconstruction not used #83

Open trosos opened 2 years ago

trosos commented 2 years ago

I believe that I maybe found a bug in the compiler.

Steps to reproduce:

cat > puzzle.cl <<EOF
(mod params
 (defun ident (arg)
  (f (list arg))
 )

 (ident (ident params))
)
EOF

run puzzle.cl

Expected result:

I expect a CLVM puzzle to be written to stdout, which would output its solution when passed to brun (i.e. "identity puzzle").

Actual results:

The run command fails with the following message:

FAIL: first of non-cons 1

Some more insight:

When I modify the puzzle in either one of the following ways, then it translates and the resulting CLVM behaves as expected:

  1. (f (list arg)) -> (f arg)
  2. (f (list arg)) -> (list arg)
  3. (f (list arg)) -> (f (f arg))
  4. (f (list arg)) -> (list (list arg))
  5. (f (list arg)) -> (list (f arg))
  6. (ident (ident params)) -> (ident params)
  7. (mod params ...) -> (mod (params) ...)

Please note that the documentation admits any of the following possibilities:

Quoting https://chialisp.com/docs/high_level_lang#squaring-a-list:

You can name each parameter in a list or you can name the list itself. This works at any place where you name parameters, and allows you to handle lists where you aren't sure of the size.

prozacchiwawa commented 2 years ago

thanks i have a candidate fix for this fairly certain it's a stray bug introduced in the conversion to rust pr: https://github.com/Chia-Network/clvm_tools_rs/pull/65