gobra icon indicating copy to clipboard operation
gobra copied to clipboard

Viper type error when encoding struct constructor with nil values

Open ArquintL opened this issue 9 months ago • 1 comments

The following two inputs lead to a type-error in the resulting Viper encoding (detectable via --checkConsistency) or, if undetected, result in a crash of Silicon / the prover.

package ex1

type PrefixTree struct {
	Value *[32]byte
	Left *PrefixTree
}

func test() (tree *PrefixTree) {
    tree = &PrefixTree{nil, nil}
    return
}

package ex2

type PrefixLeaf struct {
	Vrf_output [32]byte
	Commitment [32]byte
}

type PrefixTree struct {
	Value *[32]byte
	Leaf *PrefixLeaf
}

func test() (tree *PrefixTree) {
    tree = &PrefixTree{nil, nil}
    return
}

Observations:

  • PrefixTree needs at least 2 struct fields
  • &PrefixTree{nil, nil} is causing the error. The error does not appear when using &PrefixTree{} instead

ArquintL avatar Apr 16 '25 08:04 ArquintL

I thought this is a fairly recent regression but I can't find the commit on which it worked:

  • Reproducible on latest master commit: ac4a94b21f2f3e55bd8c7299ae9fbc422e999d41
  • Reproducible on latest hyperGobra commit: 151a1852991acd9966db402b9e4819b1bbe9b1c0
  • Reproducible on hyperGobra commit 8facab51220570ff88f72e71e794bcb336208e47

ArquintL avatar Apr 16 '25 08:04 ArquintL