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

[crypto] Unify Narwhal and Sui Crypto #2994

Merged
merged 23 commits into from
Jul 21, 2022
Merged

[crypto] Unify Narwhal and Sui Crypto #2994

merged 23 commits into from
Jul 21, 2022

Conversation

punwai
Copy link
Contributor

@punwai punwai commented Jul 6, 2022

This PR relies on: https://github.com/MystenLabs/narwhal/pull/460/files

  • All implementations of cryptographic primitives are moved over to the Narwhal repository (except AccountSignatures/Signature for now). Authority Signatures are now completely generic.
  • Added 'batch verification' on another PR in narwhal that will allow us to plug any batched signature into Sui
  • More generic and cleaner version of add bls signatures support #2877

Next to dos:

  • Change PublicKeyBytes to an Associated Type? This will massively help me out when implementing other things

crates/sui-types/src/crypto.rs Outdated Show resolved Hide resolved
crates/sui-types/src/crypto.rs Outdated Show resolved Hide resolved
@punwai punwai force-pushed the integrate-narwhal branch from c14329f to c4be662 Compare July 6, 2022 02:32
crates/sui-types/src/crypto.rs Outdated Show resolved Hide resolved
crates/sui-types/src/crypto.rs Outdated Show resolved Hide resolved
@punwai punwai force-pushed the integrate-narwhal branch 3 times, most recently from 9ecb349 to f7077e0 Compare July 6, 2022 03:00
@punwai punwai changed the title integrate narwhal crypto (WIP) integrate narwhal crypto Jul 7, 2022
@punwai
Copy link
Contributor Author

punwai commented Jul 7, 2022

@kchalkias @huitseeker Would love if you could have a look through this!

@punwai punwai changed the title integrate narwhal crypto Integrate Narwhal Crypto + BLS Jul 8, 2022
@punwai punwai changed the title Integrate Narwhal Crypto + BLS Integrate Narwhal Crypto + enable BLS Jul 9, 2022
@punwai punwai changed the title Integrate Narwhal Crypto + enable BLS Integrate Narwhal Crypto + Enable BLS Jul 9, 2022
@punwai punwai changed the title Integrate Narwhal Crypto + Enable BLS Integrate Narwhal Crypto Jul 12, 2022
@punwai punwai changed the title Integrate Narwhal Crypto [crypto] Unify Narwhal and Sui Crypto Jul 14, 2022
@huitseeker huitseeker self-assigned this Jul 16, 2022
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

Promising ! 🚀

crates/sui-benchmark/src/benchmark/bench_types.rs Outdated Show resolved Hide resolved
crates/sui-benchmark/src/benchmark/bench_types.rs Outdated Show resolved Hide resolved
crates/sui-benchmark/src/benchmark/validator_preparer.rs Outdated Show resolved Hide resolved
crates/sui-types/src/base_types.rs Outdated Show resolved Hide resolved
@punwai punwai force-pushed the integrate-narwhal branch 2 times, most recently from 3ea1692 to 4832146 Compare July 18, 2022 15:40
@punwai punwai requested a review from Clay-Mysten as a code owner July 18, 2022 15:40
@github-actions github-actions bot added the Type: Documentation Improvements or additions to documentation label Jul 18, 2022
@punwai punwai force-pushed the integrate-narwhal branch from 05b5ebe to 1d63be3 Compare July 18, 2022 16:24
@github-actions github-actions bot removed the Type: Documentation Improvements or additions to documentation label Jul 18, 2022
crates/sui-config/src/builder.rs Show resolved Hide resolved
impl From<PublicKeyBytes> for SuiAddress {
fn from(key: PublicKeyBytes) -> SuiAddress {
impl ToAddress for PublicKeyBytes {
fn to_address(&self) -> SuiAddress {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required because of polymorphism

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get it: neither rust not me have any issue with

impl From<&PublicKeyBytes> for SuiAddress {
    fn from(pkb: &PublicKeyBytes) -> Self {
        let mut hasher = Sha3_256::default();
        hasher.update(pkb.as_ref());
        let g_arr = hasher.finalize();

        let mut res = [0u8; SUI_ADDRESS_LENGTH];
        res.copy_from_slice(&AsRef::<[u8]>::as_ref(&g_arr)[..SUI_ADDRESS_LENGTH]);
        SuiAddress(res)
    }
}

what's the idea that drove you to this?

You can also use this alongside the first:


impl From<&PublicKey> for SuiAddress {
    fn from(pkb: &PublicKey) -> Self {
        let mut hasher = Sha3_256::default();
        hasher.update(pkb.as_ref());
        let g_arr = hasher.finalize();

        let mut res = [0u8; SUI_ADDRESS_LENGTH];
        res.copy_from_slice(&AsRef::<[u8]>::as_ref(&g_arr)[..SUI_ADDRESS_LENGTH]);
        SuiAddress(res)
    }
}

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 think the problem was me trying to implement PublicKey when it was a derivation of Keypair. I don't quite understand why that was a problem, but now that we remove all that gunk we should be fine.

crates/sui-types/src/messages.rs Outdated Show resolved Hide resolved
crates/sui-types/src/crypto.rs Show resolved Hide resolved
@punwai punwai force-pushed the integrate-narwhal branch 2 times, most recently from f5f3128 to 443515c Compare July 18, 2022 20:01
@punwai punwai force-pushed the integrate-narwhal branch from d212a3c to bd3d5d9 Compare July 21, 2022 06:01
@punwai punwai force-pushed the integrate-narwhal branch from cbce7f3 to 6c8ab45 Compare July 21, 2022 06:35
@punwai punwai enabled auto-merge (squash) July 21, 2022 06:37
Copy link
Collaborator

@kchalkias kchalkias left a comment

Choose a reason for hiding this comment

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

Amazing! good to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants