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

chore: Add HashPointToBytes method #428

Merged
merged 4 commits into from
Feb 29, 2024

Conversation

kevaundray
Copy link
Collaborator

@kevaundray kevaundray commented Feb 17, 2024

Rationale

We currently have two ways to convert a Point to 32 bytes, using the .Bytes method and the MapToScalarField method. The latter requires you to serialize the scalar field, though you can think of it as 32 bytes.

~~For all intents and purposes in the verkle API, it seems we only need one of these. The root node uses the former, but for other internal nodes we use the latter. This PR changes it so that the root node is not treated differently from the other internal nodes and this allows us to remove .Bytes from the public API*. ~~

It is still used when serializing proofs, but from the point of view of a verkle trie library, a proof is(should be) just an opaque set of bytes.

*This PR alone won't allow us to remove .Bytes -- it is used in pedersen_hash/get_tree_key_hash. I'll make a PR to remove it from geth.

Linking to crate-crypto/rust-verkle#86

EDIT:

Ignacio pointed out that Serialize/Bytes is needed because we need to deserialize the root node in the header in order to use it in a proof.

@kevaundray kevaundray changed the title chore!: Replace usage of Bytes method on Points with MapToScalarFieldBytes chore!: Replace usage of Bytes method on the Point struct with MapToScalarFieldBytes Feb 17, 2024
tree.go Outdated
Comment on lines 1621 to 1623
// TODO: hash.Bytes() and MapToScalarFieldBytes(n.commitment) should give the same value
// TODO: its not clear why both values were needed before this change
// TODO: hash.Bytes should likely use BytesLE to be consistent with LE format
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nit: remove TODO

ipa.go Outdated
@@ -60,3 +60,9 @@ func FromBytes(fr *Fr, data []byte) {
copy(aligned[32-len(data):], data)
fr.SetBytes(aligned[:])
}

func MapToScalarFieldBytes(point *Point) [32]byte {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whether it should go into go-ipa can be bikeshedded imo -- main goal is to update all libraries to have this breaking change

tree_test.go Outdated Show resolved Hide resolved
ipa.go Outdated Show resolved Hide resolved
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
@kevaundray kevaundray force-pushed the kw/use-hash-commitment-for-root branch from 35d8e5f to 58815f7 Compare February 29, 2024 11:59
@kevaundray kevaundray changed the title chore!: Replace usage of Bytes method on the Point struct with MapToScalarFieldBytes chore!: Add MapToScalarFieldBytes method Feb 29, 2024
@kevaundray kevaundray changed the title chore!: Add MapToScalarFieldBytes method chore: Add MapToScalarFieldBytes method Feb 29, 2024
@kevaundray
Copy link
Collaborator Author

The MapToScalarFIeldBytes method is now only added so that it can be used downstream for get_tree_key_hash/pedersen_hash

Copy link
Collaborator

@jsign jsign left a comment

Choose a reason for hiding this comment

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

LGTM. Left my 2c reg the API name.

@kevaundray kevaundray marked this pull request as ready for review February 29, 2024 13:31
@kevaundray kevaundray changed the title chore: Add MapToScalarFieldBytes method chore: Add HashPointToBytes method Feb 29, 2024
@kevaundray kevaundray merged commit a519cc4 into master Feb 29, 2024
7 checks passed
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