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

[wip] SSZ-optimize proof (type 1) #441

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

gballet
Copy link
Member

@gballet gballet commented Jul 10, 2024

This is the first suggestion by Péter, it replaces the proposed suffix diff format with:

type StemStateDiff struct {
	Stem     [StemSize]byte `json:"stem"`
	SuffixDiffs SuffixStateDiffs `json:"suffixDiffs"`
	Suffixes []byte         `json:"suffixes"`
	Current  [][]byte       `json:"current"`
	New      [][]byte       `json:"new"`
}

The size improvement compared to the currently proposed method, is significant:

image

The comparison is a bit unfair, since the library doesn't support optionals and so the encoding for the default method is greatly inflated. But one could argue that if optionals can not be implemented, then this is the correct size of the witness.

@gballet gballet requested a review from jsign July 19, 2024 08:00
type StemStateDiff struct {
Stem [StemSize]byte `json:"stem"`
SuffixDiffs SuffixStateDiffs `json:"suffixDiffs"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, now makes sense. The PR description has a small mistake that you might want to fix. Delete the SuffixDiffs SuffixStateDiffs json:"suffixDiffs" line since this field is removed.

SuffixDiffs SuffixStateDiffs `json:"suffixDiffs"`
Stem [StemSize]byte `json:"stem"`
Suffixes []byte `json:"suffixes"`
Current [][]byte `json:"current"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remember that a proof verifier must now check that []byte has length 32 which was implicit in the type before.

copy(ret[i].Suffixes, sd[i].Suffixes)
ret[i].Current = make([][]byte, len(sd[i].Current))
for j := range sd[i].Current {
if len(sd[i].Current[j]) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Remove this empty case, and only leave the else.

if len(sd[i].Current[j]) == 0 {

} else {
copy(ret[i].Current[j], sd[i].Current[j])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a bug here? We never allocated ret[i].Current[j] so it's an empty slice. The copy will copy the number of bytes being minimum between the two parameters, thus 0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in SerializeProof an append is done, which is correct since it will grow as needed compared to this copy.

Comment on lines +110 to 114
if len(sd[i].New[j]) == 0 {

} else {
copy(ret[i].New[j], sd[i].New[j])
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto two comments above.

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

Successfully merging this pull request may close these issues.

2 participants