fastssz icon indicating copy to clipboard operation
fastssz copied to clipboard

generator: int & int64 & uint - not supported ?

Open iurii-ssv opened this issue 1 year ago • 3 comments

I'm trying to use generator and encounter the following error(s):

  • for int
[ERR]: failed to encode storageShare: failed to encode storageShareValidatorMetadata: failed to encode storageShareValidatorMetadata: failed to encode int: could not find struct with name 'int'
shares.go:22: running "sszgen": exit status 1
  • for int64
[ERR]: failed to encode storageShare: failed to encode storageShareValidatorMetadata: failed to encode storageShareValidatorMetadata: failed to encode int64: could not find struct with name 'int64'
shares.go:22: running "sszgen": exit status 1
  • for uint
[ERR]: failed to encode storageShare: failed to encode storageShareValidatorMetadata: failed to encode storageShareValidatorMetadata: failed to encode uint: could not find struct with name 'uint'
shares.go:22: running "sszgen": exit status 1

It seems uint64 works fine, is there a reason those 3 can't be ssz-encoded ?

iurii-ssv avatar Nov 03 '24 11:11 iurii-ssv

Can you share a repro of the struct that fails?

ferranbt avatar Nov 04 '24 09:11 ferranbt

What's also curious is that latest version seems to be 0.1.3 while 0.1.4 seems to have been out for a while now as per https://github.com/ferranbt/fastssz/tags

➜ go install github.com/ferranbt/fastssz/sszgen@latest
...
➜ sszgen version
0.1.3

looking more into it - I believe the issue is only showing up when struct fields start with capital letter (and have int or int64 or uint type):

package storage

//go:generate sszgen -path ./shares.go --objs storageShare

type storageShare struct {
	// intExample working fine
	intExample int
	// int64Example working fine
	int64Example int64
	// uintExample working fine
	uintExample uint

	// IntExample not working fine
	IntExample int
	// Int64Example not working fine
	Int64Example int64
	// UintExample not working fine
	UintExample uint

	Layer2Struct layer2Struct
}

type layer2Struct struct {
	// intExample working fine
	intExample int
	// int64Example working fine
	int64Example int64
	// uintExample working fine
	uintExample uint

	// IntExample not working fine
	IntExample int
	// Int64Example not working fine
	Int64Example int64
	// UintExample not working fine
	UintExample uint
}

iurii-ssv avatar Nov 04 '24 10:11 iurii-ssv

I was able to reproduce it. There are two issues:

  • Uint need to specify the amount of bytes.
  • I do not think signed integers are part of the SSZ spec.

ferranbt avatar Nov 06 '24 12:11 ferranbt