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

Create a JSON RPC API for threshold-BLS signing & add the Randomness Move module #6824

Merged
merged 14 commits into from
Jan 25, 2023

Conversation

benr-ml
Copy link
Contributor

@benr-ml benr-ml commented Dec 15, 2022

Implementation of TBlsSignatureApi and the Move side according to the HLD. Currently computes everything locally, without calling f+1 validators.
Includes also examples of a lottery and an auto generated NFTs using owned objects.

@vercel
Copy link

vercel bot commented Dec 15, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

4 Ignored Deployments
Name Status Preview Comments Updated
explorer ⬜️ Ignored (Inspect) Jan 25, 2023 at 3:31PM (UTC)
explorer-storybook ⬜️ Ignored (Inspect) Jan 25, 2023 at 3:31PM (UTC)
frenemies ⬜️ Ignored (Inspect) Jan 25, 2023 at 3:31PM (UTC)
wallet-adapter ⬜️ Ignored (Inspect) Jan 25, 2023 at 3:31PM (UTC)

@benr-ml benr-ml changed the title Create a JSON RPC API for threshold-BLS signing [WIP] Create a JSON RPC API for threshold-BLS signing Dec 15, 2022
crates/sui-json-rpc/src/api.rs Show resolved Hide resolved
crates/sui-json-rpc/src/api.rs Show resolved Hide resolved
@@ -94,6 +95,66 @@ async fn test_public_transfer_object() -> Result<(), anyhow::Error> {
Ok(())
}

// TODO: WIP, complete this tests
#[sim_test]
Copy link
Contributor

Choose a reason for hiding this comment

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

probably ok to have this be sui_test so it can be run under a bare cargo test

@benr-ml benr-ml force-pushed the ben/tbls_json_rpc branch 6 times, most recently from 342cbbf to f93d4e2 Compare December 19, 2022 22:21
@benr-ml benr-ml changed the title [WIP] Create a JSON RPC API for threshold-BLS signing [WIP] Create a JSON RPC API for threshold-BLS signing & add the Randomness Move module Dec 20, 2022
@benr-ml benr-ml force-pushed the ben/tbls_json_rpc branch 2 times, most recently from 37446c3 to 2184b4b Compare January 8, 2023 18:26
@benr-ml benr-ml force-pushed the ben/tbls_json_rpc branch 2 times, most recently from f742c06 to 9fdeda3 Compare January 11, 2023 14:26
@benr-ml benr-ml marked this pull request as ready for review January 11, 2023 14:33
@benr-ml benr-ml requested review from bmwill and damirka January 11, 2023 14:33
@benr-ml
Copy link
Contributor Author

benr-ml commented Jan 11, 2023

@damirka, this is the implementation of the Randomness object we discussed awhile ago. Would appreciate your review of the Move related files.

@bmwill, updated the PR after some changes I've done in fastcrypto that blocked this change. I'm planning to fix the TODO on verifying the effects cert in a follow up PR.

@benr-ml benr-ml changed the title [WIP] Create a JSON RPC API for threshold-BLS signing & add the Randomness Move module Create a JSON RPC API for threshold-BLS signing & add the Randomness Move module Jan 11, 2023
@benr-ml benr-ml force-pushed the ben/tbls_json_rpc branch 3 times, most recently from 7ffb058 to 056c4ae Compare January 22, 2023 08:56
@benr-ml benr-ml requested a review from patrickkuo January 24, 2023 14:53
Copy link
Contributor

@damirka damirka left a comment

Choose a reason for hiding this comment

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

Amazing work! Move part is done well!

Left a few comments but feel free to ignore.

crates/sui-framework/tests/crypto/randomness_tests.move Outdated Show resolved Hide resolved
crates/sui-framework/sources/crypto/randomness.move Outdated Show resolved Hide resolved
sui_programmability/examples/nfts/sources/random_word.move Outdated Show resolved Hide resolved
sui_programmability/examples/nfts/sources/random_word.move Outdated Show resolved Hide resolved
const EInvalidRndLength: u64 = 2;

/// All signatures are prefixed with Domain.
const Domain: vector<u8> = b"randomness";
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this needs to be static or dynamic (probably former) but you can use type of the T as a signing parameter through type reflection:

let unique_type_signature: TypeName = std::type_name::get<T>();
// and then something like
let bytes = sui::bcs::to_bytes(&unique_type_signature);

crates/sui-framework/sources/crypto/randomness.move Outdated Show resolved Hide resolved
}

/// Verify signature sig on message msg using the epoch's BLS key.
native fun native_tbls_verify_signature(epoch: u64, msg: &vector<u8>, sig: &vector<u8>): bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these functions are relatively important (although not available publicly, it might be better to move them up for visibility).

Copy link
Contributor

@patrickkuo patrickkuo left a comment

Choose a reason for hiding this comment

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

Some nits on error handling, otherwise LGTM

crates/sui-json-rpc/src/api.rs Show resolved Hide resolved
.await
.map_err(|e| anyhow!(e))?;
let ObjectRead::Exists(_obj_ref, obj, layout) = obj_read else {
Err(anyhow!("Object not found"))? };
Copy link
Contributor

Choose a reason for hiding this comment

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

if you return Result<Object,Error> instead of RpcResult, you can use a proper error (SuiError or sui-json-rpc::Error) instead of Err(anyhow!())?, e.g.

async fn get_object(&self, object_id: &ObjectID) -> Result<Object, Error> {
Ok(self.state.get_object_read(object_id).await?.into_object()?)
}

Copy link
Contributor Author

@benr-ml benr-ml Jan 25, 2023

Choose a reason for hiding this comment

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

I changed the function response (here and elsewhere) and used enums for "canonical errors" and anyhow for user specific ones.

crates/sui-json-rpc/src/threshold_bls_api.rs Show resolved Hide resolved
crates/sui-json-rpc/src/threshold_bls_api.rs Outdated Show resolved Hide resolved
@benr-ml benr-ml requested a review from patrickkuo January 25, 2023 14:59
Copy link
Contributor

@patrickkuo patrickkuo left a comment

Choose a reason for hiding this comment

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

LGTM!

@benr-ml benr-ml merged commit abb34e8 into main Jan 25, 2023
@benr-ml benr-ml deleted the ben/tbls_json_rpc branch January 25, 2023 15:55
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.

4 participants