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

sszgen: max size shadowed by first occurence of custom type def #75

Closed
lightclient opened this issue May 17, 2022 · 7 comments
Closed

Comments

@lightclient
Copy link

Bytes []byte

type A struct {
        Foo Bytes `ssz-max:"2048"`
}

type B struct {
        Bar Bytes `ssz-max:"32"`
}

If you run sszgen on these structs, both A and B will use 2048 as the max size for the byte list. In the case of B, this causes an incorrect hash-tree-root to be calculated, because the mix in should be based on 32, not `2048.

@lightclient lightclient changed the title sszgen shadows max size of type defs sszgen: max size shadowed by first occurence of custom type def May 17, 2022
@lightclient
Copy link
Author

It's also making a MarshalSSZ method with an offset that is never used:

func (b *Bytes) MarshalSSZTo(buf []byte) (dst []byte, err error) {
    dst = buf
    offset := int(4)

    return
}

@ferranbt
Copy link
Owner

Which commit of sszgen are you using? I am trying with the latest sszgen but I get a different error.

@lightclient
Copy link
Author

lightclient commented May 18, 2022

@ferranbt I'm using the sszgen given by go install github.com/ferranbt/fastssz/sszgen@latest

edit: compiled from 780dd73 and was able to replicate the issue? What error are you seeing that differs?

@ferranbt
Copy link
Owner

Fixed in #76. There are two things here:

  • There was an error indeed on the tags being reused for the other object. This one is fixed.
  • The object Bytes cannot ever be ssz generated since it requires tags. You would have to skip it with --exclude-objs flag.

@lightclient
Copy link
Author

Great - thank you @ferranbt. Will --exclude-objs also resolve the following issue:

import "github.com/ethereum/go-ethereum/common/hexutil"

type A struct {
        Foo hexutil.Bytes `ssz-max:"2048"`
}

type B struct {
        Bar hexutil.Bytes `ssz-max:"32"`
}

and sszgen --include ../go-ethereum/common/hexutil --path . --objs A,B causes the resulting encoding file to have the error

./main_encoding.go:6:2: imported and not used: "github.com/ethereum/go-ethereum/common/hexutil"

@ferranbt
Copy link
Owner

Ok, now this is a different thing hahah. I was wondering if that Bytes object would come from a different place. In this case, you do not need to use --exclude-objs since it is not part of the main source. Do you mind opening another issue regarding this?

@lightclient
Copy link
Author

Yes I will

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants