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

Integrate libsodium (Algorand's VRF lib) into Tendermint #4

Closed
wants to merge 11 commits into from

Conversation

torao
Copy link
Contributor

@torao torao commented Nov 28, 2019

This PR on #1, #2 allows us to call the library libsodium implemented in C from within the Tendermint project. This contains golang functions that are equivalent to the VRF functions defined in libsodium.

Note that the libsodium used in this PR is a cryptography library of the same name with VRF capability (IRFT Draft 3) added by Algorand. The original libsodium does not contain a VRF.

In a newly checked out environment, libsodium must be built and installed before compiling golang.

$ cd crypto/vrf/internal/vrf/libsodium
$ ./autogen.sh
$ ./configure
$ make && make check
$ sudo make install

@torao torao self-assigned this Nov 28, 2019
@torao torao added the C: enhancement Classification: New feature or its request, or improvement in maintainability of code label Nov 28, 2019
@torao torao added this to the Evolve Leader Election into VRF milestone Nov 28, 2019
@tnasu tnasu mentioned this pull request Dec 5, 2019
20 tasks
@torao torao force-pushed the feature/integrate_libsodium branch from faaf139 to 10bcded Compare December 10, 2019 10:22
@torao
Copy link
Contributor Author

torao commented Dec 11, 2019

local unit-test passed

Copy link
Member

@tnasu tnasu left a comment

Choose a reason for hiding this comment

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

LGTM

@egonspace egonspace self-requested a review December 13, 2019 01:10
messagePtr := (*C.uchar)(unsafe.Pointer(&message))
messageLen := (C.ulonglong)(len(message))
if C.crypto_vrf_prove(proofPtr, privateKeyPtr, messagePtr, messageLen) != 0 {
return nil, errors.New(fmt.Sprintf("unable to decode the given privateKey: %s",
Copy link
Contributor

Choose a reason for hiding this comment

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

If some error can be raised with correct privateKey and wrong message, printing private key in log is not good for security reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, I'll fix it.

if err3 != nil {
t.Errorf("failed to verify: %s", err3)
} else if ! bytes.Equal(hash1[:], hash2[:]) {
t.Errorf("output incompativle: %s != %s", enc(hash1[:]), enc(hash2[:]))
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: incompativle
and I am asking for just wonder, is the result of verifying same to proof?

Copy link
Contributor Author

@torao torao Jan 6, 2020

Choose a reason for hiding this comment

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

fix it.
Yes, the outputs of proof_to_hash() and verify() must exactly match for a valid proof pi. According to the IETF draft 4:

Thus, the VRF also comes with an algorithm

VRF_verify(PK, alpha, pi)

that outputs (VALID, beta = VRF_proof_to_hash(pi)) if pi is valid, and INVALID otherwise."

privateKeyPtr := (*C.uchar)(unsafe.Pointer(privateKey))
C.crypto_vrf_sk_to_seed(seedPtr, privateKeyPtr) // void
return &seed
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that VRF has four functions(hash(), prove(), proofToHash(), verify()). But I cannot see hash() function in this file. Must the prover use proofToHash() rather than hash() to get beta?

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, it is. This PR is to integrate the libsodium API and the library doesn't provide a hash() function. I think this is because hash() can be composited from prove() and hash_to_poof(). This probably follows the IETF policy.

Notice that this means that

 VRF_hash(SK, alpha) = VRF_proof_to_hash(VRF_prove(SK, alpha))

and thus this document will specify VRF_prove and VRF_proof_to_hash
rather than VRF_hash.

@torao torao force-pushed the feature/integrate_libsodium branch from 100ef8e to 1fecb81 Compare January 6, 2020 10:51
@zemyblue
Copy link
Member

zemyblue commented Jan 8, 2020

CircleCI normalize 🎉

Changes

  • Add pulling submodules.
  • Add the function that compile libsodium
  • Change the libsodium library path to /include and /lib of ./crypto/vrf/internal/vrf/
  • Comments out coverage report. (temporary prohibit for distinguishing with origin tendermint. I'll ready other solution later.)

@zemyblue zemyblue mentioned this pull request Jan 8, 2020
2 tasks
@tnasu
Copy link
Member

tnasu commented Jan 9, 2020

BTW, where are our commits? I think this PR is difficult to understand our changes... I'm afraid to squash 224 commits...

@zemyblue
Copy link
Member

zemyblue commented Jan 9, 2020

BTW, where are our commits? I think this PR is difficult to understand our changes... I'm afraid to squash 224 commits...

How about merge #11 first?
And then if merge from latest master branch, the origin changes will be disappeared.

@zemyblue
Copy link
Member

zemyblue commented Jan 9, 2020

Now, we can see only our changes. 😀
Thanks all.

@torao
Copy link
Contributor Author

torao commented Jan 9, 2020

This PR became complicated by a number of commits and rebases, so we move to a new one #12.

@torao torao closed this Jan 9, 2020
@tnasu
Copy link
Member

tnasu commented Jan 9, 2020

wow, you can rebase using git command and force push on this PR...

@torao torao deleted the feature/integrate_libsodium branch June 22, 2020 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: enhancement Classification: New feature or its request, or improvement in maintainability of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants