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

Compact Precise Proofs #743

Merged
merged 8 commits into from Feb 13, 2019
Merged

Compact Precise Proofs #743

merged 8 commits into from Feb 13, 2019

Conversation

mikiquantum
Copy link
Contributor

Issue Link:

@@ -16,6 +16,41 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
)

const (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Disregard this file.

@@ -215,10 +215,11 @@ func TestNewWithCollaborators(t *testing.T) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Disregard this file.

@@ -18,6 +18,22 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
)

const (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As sometimes we create the tree manually, we have to provide a deterministic compact name to each of the fields. Some of them might have a correspondent field in the coredocument and some dont. This keeps a map of the literal name and the compact name.

Copy link
Member

Choose a reason for hiding this comment

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

Not an immediate action item, but we have to make sure that we don't accidentally create two fields with the same property (one in invoice and one in CoreDoc for example).

We could achieve this using reserved statements and putting field numbers into there for the fields of the other documents.

message Foo {
  reserved 2, 15, 9 to 11;
  reserved "foo", "bar";
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, agree the initial definition of the protocol documents should have that defined upfront. In this particular case, for low level general fields, I would argue to have those fields defined in the coredoc proto message, even though they are calculated every time.

@@ -53,6 +69,27 @@ const (
ErrZeroCollaborators = errors.Error("require at least one collaborator")
)

// NewDefaultTree returns a DocumentTree with default opts
func NewDefaultTree(salts *proofs.Salts) *proofs.DocumentTree {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to enforce a single way of creating a tree with the supported defaults. Here is the methods we should be using.

}

// NewLeafProperty returns a proof property with the literal and the compact
func NewLeafProperty(literal string, compact []byte) proofs.Property {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same for creating custom properties, I wanted to enforce that we always pass the compact name as well

@@ -287,18 +287,20 @@ func TestGetDocumentRootTree(t *testing.T) {
tree, err := dm.GetDocumentRootTree()

// Manually constructing the two node tree:
signaturesLengthLeaf := sha256.Sum256(append([]byte("signatures.length0"), make([]byte, 32)...))
expectedRootHash := sha256.Sum256(append(signaturesLengthLeaf[:], dm.Document.SigningRoot...))
signaturesLengthLeaf := sha256.Sum256(append(append(compactProperties[SignaturesField], []byte{48}...), make([]byte, 32)...))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like with the new precise proof update the order of hashing leaves has changed.

Copy link
Member

Choose a reason for hiding this comment

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

But why did you say the order has changed?

Copy link
Member

Choose a reason for hiding this comment

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

It's property, value, salt. Was it different before?

Actually []byte{48} -> seems to be the wrong length value here, that to me looks like an ASCII encoded "SPACE" character and not a 0. Though this will be fixed when changing the way we generate the signatures. So not worth fixing I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

within leaves, not within a leaf. Not sure why but if you look at the next line 291 I had to change the order.
Regarding the ascii code, int(48) is 0 in ASCII, as the node logic for length fields does: []byte("0"). I could transform that to encode an int in bytes today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this should be addressed once we create the signatures as a tree soon.

Copy link
Member

@lucasvo lucasvo left a comment

Choose a reason for hiding this comment

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

None of the changes need to be addressed in this PR but definitely need to be fixed pretty soon I think in follow up work.

@@ -18,6 +18,22 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
)

const (
Copy link
Member

Choose a reason for hiding this comment

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

Not an immediate action item, but we have to make sure that we don't accidentally create two fields with the same property (one in invoice and one in CoreDoc for example).

We could achieve this using reserved statements and putting field numbers into there for the fields of the other documents.

message Foo {
  reserved 2, 15, 9 to 11;
  reserved "foo", "bar";
}

}

func NewDefaultTreeWithPrefix(salts *proofs.Salts, prefix string) *proofs.DocumentTree {
var prop proofs.Property
Copy link
Member

Choose a reason for hiding this comment

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

Technically we also have to prefix the compact version of the properties so we'll need to have a byte and string prefix. I think it's fine to implement this in a later PR but it's something we should think about. Perhaps we actually can pass in a Property as a prefix instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I will add another entry in the map for our prefixes used as a "reserved" prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -287,18 +287,20 @@ func TestGetDocumentRootTree(t *testing.T) {
tree, err := dm.GetDocumentRootTree()

// Manually constructing the two node tree:
signaturesLengthLeaf := sha256.Sum256(append([]byte("signatures.length0"), make([]byte, 32)...))
expectedRootHash := sha256.Sum256(append(signaturesLengthLeaf[:], dm.Document.SigningRoot...))
signaturesLengthLeaf := sha256.Sum256(append(append(compactProperties[SignaturesField], []byte{48}...), make([]byte, 32)...))
Copy link
Member

Choose a reason for hiding this comment

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

But why did you say the order has changed?

@@ -287,18 +287,20 @@ func TestGetDocumentRootTree(t *testing.T) {
tree, err := dm.GetDocumentRootTree()

// Manually constructing the two node tree:
signaturesLengthLeaf := sha256.Sum256(append([]byte("signatures.length0"), make([]byte, 32)...))
expectedRootHash := sha256.Sum256(append(signaturesLengthLeaf[:], dm.Document.SigningRoot...))
signaturesLengthLeaf := sha256.Sum256(append(append(compactProperties[SignaturesField], []byte{48}...), make([]byte, 32)...))
Copy link
Member

Choose a reason for hiding this comment

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

It's property, value, salt. Was it different before?

Actually []byte{48} -> seems to be the wrong length value here, that to me looks like an ASCII encoded "SPACE" character and not a 0. Though this will be fixed when changing the way we generate the signatures. So not worth fixing I think.

@codecov
Copy link

codecov bot commented Feb 13, 2019

Codecov Report

Merging #743 into develop will increase coverage by 0.06%.
The diff coverage is 94%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #743      +/-   ##
===========================================
+ Coverage     52.2%   52.26%   +0.06%     
===========================================
  Files          119      119              
  Lines         9110     9216     +106     
===========================================
+ Hits          4756     4817      +61     
- Misses        3802     3842      +40     
- Partials       552      557       +5
Impacted Files Coverage Δ
documents/invoice/model.go 88.18% <100%> (-0.06%) ⬇️
documents/handler.go 85.45% <100%> (ø) ⬆️
documents/purchaseorder/model.go 83.41% <100%> (-0.08%) ⬇️
coredocument/coredocument.go 69.29% <89.47%> (-0.19%) ⬇️
documents/model.go 73.07% <95.83%> (+0.47%) ⬆️
identity/did/service.go 42.4% <0%> (-12.39%) ⬇️
identity/did/key.go 46.15% <0%> (-8.4%) ⬇️
identity/did/factory.go 45.33% <0%> (-7.7%) ⬇️
bootstrap/bootstrappers/bootstrapper.go 5.12% <0%> (-0.14%) ⬇️
identity/identity.go 87.69% <0%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e3cb95...5bdb1fe. Read the comment docs.

@mikiquantum mikiquantum merged commit 0956e7a into centrifuge:develop Feb 13, 2019
@mikiquantum mikiquantum deleted the compact branch February 13, 2019 13:14
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.

None yet

2 participants