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

Make ECChain opaque [][]byte in GBPFT #149

Merged
merged 4 commits into from
Apr 10, 2024
Merged

Make ECChain opaque [][]byte in GBPFT #149

merged 4 commits into from
Apr 10, 2024

Conversation

anorth
Copy link
Member

@anorth anorth commented Apr 2, 2024

Removes all internal structure from ECTipset and ECChain, making them entirely opaque. Adds a key type which just stringifies the bytes, ensuring that the entire value is used as a map key. Note that this doesn't yet exactly match the draft FIP (#148).

The internal structure of chain values now needs to be specified elsewhere, but GPBFT will never introspect it.

This also deleted some useful tests for the consistency of chains. When a new type is introduces at the integration layer, those tests should be restored there instead.

Previous PR description below (just introduces the key type) :

This is a prototype of using the full ECChain payload as a map key, rather than just head tipset ID. It avoids hashing, but just concatenates the bytes and wraps as a string.

This also changes the TipsetID type to be [][]byte, removing an additional serialization step and, by design, making it unusable as a map key. Note that this doesn't yet exactly match the draft FIP (#148).

Review: please critique this design and suggest alternatives. There is an outstanding problem of generating a unique key for [][]byte (for both keying and signing) that will incorporate the slice boundaries. Ideas welcome.

Closes #147.

@Stebalien
Copy link
Member

What if we just agreed on opaque byte slices and let the client deal with all the serialization and deserialization? This package doesn't actually care about the structure of the data, correct?

I.e.:

type ECChain [][]byte

@Kubuxu
Copy link
Collaborator

Kubuxu commented Apr 3, 2024

What if we just agreed on opaque byte slices and let the client deal with all the serialization and deserialization? This package doesn't actually care about the structure of the data, correct?

It might care about power table in there

@masih
Copy link
Member

masih commented Apr 3, 2024

Is there a specific reason for not removing the redundant data from phases other than QUALITY? That seems like a more optimal solution IMHO.

@Stebalien
Copy link
Member

It might care about power table in there

IMO, it shouldn't. GetCanonicalChain returns the expected power table.

@anorth
Copy link
Member Author

anorth commented Apr 4, 2024

It might care about power table in there

IMO, it shouldn't. GetCanonicalChain returns the expected power table.

Right, the protocol code never inspects the CID, and doesn't generally have access to the corresponding (non-finalised, or non-lookback) table. So @Stebalien 's suggestion is pretty good – I will try it out.

Is there a specific reason for not removing the redundant data from phases other than QUALITY?

We can still do that. I'm not not doing that, if you know what I mean. But it's a much larger change. We can try that after this, if we think it's worthwhile.

@masih
Copy link
Member

masih commented Apr 5, 2024

We can try that after this, if we think it's worthwhile.

Thank you, yes I think it is worth it.

@anorth anorth changed the title Uses the full ECChain payload as a map key Make ECChain opaque [][]byte in GBPFT Apr 8, 2024
@anorth
Copy link
Member Author

anorth commented Apr 8, 2024

type ECChain [][]byte

@Stebalien @Kubuxu @masih I've implemented this now. Please see updated PR description and re-review.

…set ID.

Changes the TipsetID type to be [][]byte, removing an additional serialization and making it unusable as a map key.
// - a commitment to the resulting power table,
// - a commitment to additional derived values.
// However, GossipPBFT doesn't need to know anything about that structure.
type TipSet = []byte
Copy link
Member

Choose a reason for hiding this comment

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

I am curious: why type alias instead of type definition?

Copy link
Member Author

@anorth anorth Apr 10, 2024

Choose a reason for hiding this comment

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

cbor-gen was unable to generate correct (compiling) code for [][]byte. A type definition would have been slightly better, but this isn't a yak I'm prepared to shave.

gpbft/chain.go Outdated Show resolved Hide resolved

func (t TipSetID) Bytes() []byte {
return []byte(t.value)
}
Copy link
Member

Choose a reason for hiding this comment

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

nice 👍

gpbft/chain.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Kubuxu Kubuxu left a comment

Choose a reason for hiding this comment

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

SGTM

@anorth anorth enabled auto-merge (squash) April 10, 2024 22:00
@anorth anorth merged commit ab3f343 into main Apr 10, 2024
3 checks passed
@Kubuxu Kubuxu deleted the anorth/chainkey branch April 24, 2024 14:11
Stebalien added a commit that referenced this pull request May 14, 2024
This patch implements the changes described in
filecoin-project/FIPs#1004.

Unfortunately, go-f3 now needs to be aware of the internal structure of
`TipSet` objects as it sends them over the wire in one format, but signs
another. This effectively reverts #149.

Specific changes:

1. On the wire (and in finality certificates), `TipSet` objects are now
   directly cbor-marshaled within the payload instead of first being
   marshaled to byte strings.
2. Instead of directly covering the entire tipset list with the payload
   signature:
  1. `TipSet` objects are "marshaled for signing" per the FIP change
      proposed above.
  2. These marshaled tipset objects are stuffed into a merkle tree.
  3. The merkle tree root is signed (along with the payload's other
     fields), again according the proposed changes.

fixes #166
Stebalien added a commit that referenced this pull request May 14, 2024
This patch implements the changes described in
filecoin-project/FIPs#1004.

Unfortunately, go-f3 now needs to be aware of the internal structure of
`TipSet` objects as it sends them over the wire in one format, but signs
another. This effectively reverts #149.

Specific changes:

1. On the wire (and in finality certificates), `TipSet` objects are now
   directly cbor-marshaled within the payload instead of first being
   marshaled to byte strings.
2. Instead of directly covering the entire tipset list with the payload
   signature:
  1. `TipSet` objects are "marshaled for signing" per the FIP change
      proposed above.
  2. These marshaled tipset objects are stuffed into a merkle tree.
  3. The merkle tree root is signed (along with the payload's other
     fields), again according the proposed changes.

fixes #166
Stebalien added a commit that referenced this pull request May 14, 2024
This patch implements the changes described in
filecoin-project/FIPs#1004.

Unfortunately, go-f3 now needs to be aware of the internal structure of
`TipSet` objects as it sends them over the wire in one format, but signs
another. This effectively reverts #149.

Specific changes:

1. On the wire (and in finality certificates), `TipSet` objects are now
   directly cbor-marshaled within the payload instead of first being
   marshaled to byte strings.
2. Instead of directly covering the entire tipset list with the payload
   signature:
  1. `TipSet` objects are "marshaled for signing" per the FIP change
      proposed above.
  2. These marshaled tipset objects are stuffed into a merkle tree.
  3. The merkle tree root is signed (along with the payload's other
     fields), again according the proposed changes.

fixes #166
Stebalien added a commit that referenced this pull request May 14, 2024
This patch implements the changes described in
filecoin-project/FIPs#1004.

Unfortunately, go-f3 now needs to be aware of the internal structure of
`TipSet` objects as it sends them over the wire in one format, but signs
another. This effectively reverts #149.

Specific changes:

1. On the wire (and in finality certificates), `TipSet` objects are now
   directly cbor-marshaled within the payload instead of first being
   marshaled to byte strings.
2. Instead of directly covering the entire tipset list with the payload
   signature:
  1. `TipSet` objects are "marshaled for signing" per the FIP change
      proposed above.
  2. These marshaled tipset objects are stuffed into a merkle tree.
  3. The merkle tree root is signed (along with the payload's other
     fields), again according the proposed changes.

fixes #166
Stebalien added a commit that referenced this pull request May 14, 2024
This patch implements the changes described in
filecoin-project/FIPs#1004.

Unfortunately, go-f3 now needs to be aware of the internal structure of
`TipSet` objects as it sends them over the wire in one format, but signs
another. This effectively reverts #149.

Specific changes:

1. On the wire (and in finality certificates), `TipSet` objects are now
   directly cbor-marshaled within the payload instead of first being
   marshaled to byte strings.
2. Instead of directly covering the entire tipset list with the payload
   signature:
  1. `TipSet` objects are "marshaled for signing" per the FIP change
      proposed above.
  2. These marshaled tipset objects are stuffed into a merkle tree.
  3. The merkle tree root is signed (along with the payload's other
     fields), again according the proposed changes.

fixes #166
github-merge-queue bot pushed a commit that referenced this pull request May 17, 2024
* EVM-friendly TipSet and ECChain formats

This patch implements the changes described in
filecoin-project/FIPs#1004.

Unfortunately, go-f3 now needs to be aware of the internal structure of
`TipSet` objects as it sends them over the wire in one format, but signs
another. This effectively reverts #149.

Specific changes:

1. On the wire (and in finality certificates), `TipSet` objects are now
   directly cbor-marshaled within the payload instead of first being
   marshaled to byte strings.
2. Instead of directly covering the entire tipset list with the payload
   signature:
  1. `TipSet` objects are "marshaled for signing" per the FIP change
      proposed above.
  2. These marshaled tipset objects are stuffed into a merkle tree.
  3. The merkle tree root is signed (along with the payload's other
     fields), again according the proposed changes.

fixes #166

* test marshal payload for signing

* slightly optimize hashing

* add a worst-case benchmark for marshalling payloads

* address feedback

* Fake marshaling for testing

* pre-allocate when marshaling tipsets

* combine signer/verifier and MarshalPayloadForSignature

Into a single Signatures interface.

* tipset marshal for signing test

* Test bad merkle-tree paths
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.

Use the whole chain when keying for proposals
4 participants