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

Pointer for programs #536

Merged
merged 51 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c171909
update program pallet
JesseAbram Nov 28, 2023
7690e9e
update relayer
JesseAbram Nov 28, 2023
0ec0232
programs tests
JesseAbram Nov 29, 2023
8f45c05
relayer tests
JesseAbram Nov 29, 2023
40b9be9
test change pointer
JesseAbram Nov 29, 2023
2d825a7
add program owner
JesseAbram Nov 30, 2023
6a7ee42
update server
JesseAbram Dec 1, 2023
eb66a9f
fix tests
JesseAbram Dec 1, 2023
b693792
remove program bench
JesseAbram Dec 1, 2023
79d2e66
add change pointer benchmark
JesseAbram Dec 1, 2023
a1588e7
fix test
JesseAbram Dec 1, 2023
9412b49
fix bench
JesseAbram Dec 1, 2023
78acd5f
clean
JesseAbram Dec 1, 2023
0d63f1b
Merge branch 'master' of github.com:entropyxyz/entropy-core into poin…
JesseAbram Dec 4, 2023
238b25f
merge master
JesseAbram Dec 4, 2023
2565300
clean
JesseAbram Dec 5, 2023
515fdb8
lint
JesseAbram Dec 5, 2023
e077711
docs
JesseAbram Dec 5, 2023
ccd9c4d
fix weight changes
JesseAbram Dec 5, 2023
d2031f8
wasm stuff
JesseAbram Dec 5, 2023
e44453e
add to changelog
JesseAbram Dec 5, 2023
195d7d5
fix tests
JesseAbram Dec 6, 2023
5b3e8cd
add program does not exist check
JesseAbram Dec 6, 2023
beac561
fix tests
JesseAbram Dec 6, 2023
1b7d512
fix tests
JesseAbram Dec 7, 2023
96bfd8d
wasm test
JesseAbram Dec 7, 2023
87b66cc
fix benchmarks
JesseAbram Dec 7, 2023
e8cf7c9
Update crypto/test-cli/src/main.rs
JesseAbram Dec 8, 2023
b198537
Update pallets/programs/src/lib.rs
JesseAbram Dec 8, 2023
b40a12d
Update crypto/testing-utils/src/test_client/mod.rs
JesseAbram Dec 8, 2023
1dd8ca2
Update crypto/testing-utils/src/test_client/mod.rs
JesseAbram Dec 8, 2023
f7d4ad2
fix
JesseAbram Dec 8, 2023
4073ab4
remove unwraps
JesseAbram Dec 8, 2023
0cd3c27
Merge branch 'master' of github.com:entropyxyz/entropy-core into poin…
JesseAbram Dec 8, 2023
560ad5b
Update pallets/programs/src/lib.rs
JesseAbram Dec 12, 2023
d2d85c5
Update pallets/programs/src/lib.rs
JesseAbram Dec 12, 2023
9d91d5c
Update pallets/programs/src/lib.rs
JesseAbram Dec 12, 2023
ee05fb5
refactors
JesseAbram Dec 12, 2023
ce5ec15
refactor
JesseAbram Dec 12, 2023
e1524bd
refactor
JesseAbram Dec 12, 2023
0def29c
refactor
JesseAbram Dec 12, 2023
bd469f0
refactors
JesseAbram Dec 12, 2023
3b19fcc
clean
JesseAbram Dec 12, 2023
e7038fd
change runtime value
JesseAbram Dec 12, 2023
6d42057
Update pallets/relayer/src/benchmarking.rs
JesseAbram Dec 12, 2023
38ebc81
Apply suggestions from code review
JesseAbram Dec 12, 2023
b601ed3
fix
JesseAbram Dec 12, 2023
9e3eb90
remove duplicate update_pointer
JesseAbram Dec 13, 2023
ebbdb55
Merge branch 'master' of github.com:entropyxyz/entropy-core into poin…
JesseAbram Dec 13, 2023
886412f
fix benchmarks
JesseAbram Dec 13, 2023
dca6cc2
Update CHANGELOG.md
JesseAbram Dec 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ At the moment this project **does not** adhere to

- Test CLI which calls the same code as in integration tests ([#417](https://github.com/entropyxyz/entropy-core/pull/417))

### Breaking Changes
HCastano marked this conversation as resolved.
Show resolved Hide resolved

- In [#536](https://github.com/entropyxyz/entropy-core/pull/536/), the registered struct no longer holds a program but rather a hash of a program that is set in the set_program function

### Added
- Pointer for Programs ([#536](https://github.com/entropyxyz/entropy-core/pull/536/))

## [0.0.9](https://github.com/entropyxyz/entropy-core/compare/release/v0.0.8..release/v0.0.9) - 2023-11-30

Some of the noteworthy changes related to this release are related to better integration in Web
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified crypto/server/entropy_metadata.scale
Binary file not shown.
78 changes: 20 additions & 58 deletions crypto/server/src/helpers/substrate.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use entropy_shared::{KeyVisibility, SIGNING_PARTY_SIZE};
use subxt::{
backend::legacy::LegacyRpcMethods, ext::sp_core::sr25519, tx::PairSigner, utils::AccountId32,
Config, OnlineClient,
};

use crate::{
chain_api::{entropy, EntropyConfig},
chain_api::{
entropy::{self, runtime_types::pallet_relayer::pallet::RegisteredInfo},
EntropyConfig,
},
user::UserErr,
};
use entropy_shared::SIGNING_PARTY_SIZE;
use subxt::{
backend::legacy::LegacyRpcMethods,
ext::sp_core::sr25519,
tx::PairSigner,
utils::{AccountId32, H256},
Config, OnlineClient,
};

/// gets the subgroup of the working validator
pub async fn get_subgroup(
Expand Down Expand Up @@ -71,72 +76,29 @@ pub async fn return_all_addresses_of_subgroup(
pub async fn get_program(
substrate_api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
sig_req_account: &<EntropyConfig as Config>::AccountId,
program_pointer: &<EntropyConfig as Config>::Hash,
) -> Result<Vec<u8>, UserErr> {
let bytecode_address = entropy::storage().programs().bytecode(sig_req_account);
let block_hash = rpc
.chain_get_block_hash(None)
.await?
.ok_or_else(|| UserErr::OptionUnwrapError("Error getting block hash".to_string()))?;
let bytecode_address = entropy::storage().programs().programs(program_pointer);

substrate_api
Ok(substrate_api
.storage()
.at(block_hash)
.fetch(&bytecode_address)
.await?
.ok_or(UserErr::NoProgramDefined)
}

/// Puts a user in the Registering state on-chain and waits for that transaction to be included in a
/// block
#[cfg(test)]
pub async fn make_register(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
sig_req_keyring: sr25519::Pair,
program_modification_account: &AccountId32,
key_visibility: KeyVisibility,
) {
use subxt::utils::Static;

let sig_req_account = PairSigner::<EntropyConfig, sr25519::Pair>::new(sig_req_keyring);

let registering_query = entropy::storage().relayer().registering(sig_req_account.account_id());
let block_hash = rpc.chain_get_block_hash(None).await.unwrap().unwrap();
let is_registering_1 = api.storage().at(block_hash).fetch(&registering_query).await.unwrap();
assert!(is_registering_1.is_none());

// register the user
let empty_program = vec![];
let registering_tx = entropy::tx().relayer().register(
program_modification_account.clone(),
Static(key_visibility),
empty_program,
);

api.tx()
.sign_and_submit_then_watch_default(&registering_tx, &sig_req_account)
.await
.unwrap()
.wait_for_in_block()
.await
.unwrap()
.wait_for_success()
.await
.unwrap();

let block_hash_2 = rpc.chain_get_block_hash(None).await.unwrap().unwrap();

let query_registering_status = api.storage().at(block_hash_2).fetch(&registering_query).await;
assert!(query_registering_status.unwrap().is_some());
.ok_or(UserErr::NoProgramDefined)?
.bytecode)
}

/// Returns a registered user's key visibility
pub async fn get_key_visibility(
pub async fn get_registered_details(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
who: &<EntropyConfig as Config>::AccountId,
) -> Result<KeyVisibility, UserErr> {
) -> Result<RegisteredInfo<H256, AccountId32>, UserErr> {
let registered_info_query = entropy::storage().relayer().registered(who);
let block_hash = rpc
.chain_get_block_hash(None)
Expand All @@ -148,5 +110,5 @@ pub async fn get_key_visibility(
.fetch(&registered_info_query)
.await?
.ok_or_else(|| UserErr::NotRegistering("Register Onchain first"))?;
Ok(result.key_visibility.0)
Ok(result)
}
14 changes: 7 additions & 7 deletions crypto/server/src/helpers/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use subxt::{
ext::sp_core::{sr25519, Pair},
tx::PairSigner,
utils::{AccountId32 as SubxtAccountId32, Static},
OnlineClient,
Config, OnlineClient,
};
use synedrion::KeyShare;
use testing_utils::substrate_context::testing_context;
Expand Down Expand Up @@ -164,19 +164,16 @@ pub async fn spawn_testing_validators(

pub async fn update_programs(
entropy_api: &OnlineClient<EntropyConfig>,
sig_req_keyring: &sr25519::Pair,
program_modification_account: &sr25519::Pair,
initial_program: Vec<u8>,
) {
) -> <EntropyConfig as Config>::Hash {
// update/set their programs
let update_program_tx = entropy::tx()
.programs()
.update_program(SubxtAccountId32::from(sig_req_keyring.public()), initial_program);
let update_program_tx = entropy::tx().programs().set_program(initial_program);

let program_modification_account =
PairSigner::<EntropyConfig, sr25519::Pair>::new(program_modification_account.clone());

entropy_api
let in_block = entropy_api
.tx()
.sign_and_submit_then_watch_default(&update_program_tx, &program_modification_account)
.await
Expand All @@ -187,6 +184,9 @@ pub async fn update_programs(
.wait_for_success()
.await
.unwrap();

let result_event = in_block.find_first::<entropy::programs::events::ProgramCreated>().unwrap();
result_event.unwrap().program_hash
}

/// Verify that a Registering account has all confirmation, and that it is registered.
Expand Down
8 changes: 6 additions & 2 deletions crypto/server/src/signing_client/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
chain_api::{entropy, get_api, get_rpc, EntropyConfig},
helpers::{
launch::LATEST_BLOCK_NUMBER_PROACTIVE_REFRESH,
substrate::{get_key_visibility, get_subgroup, return_all_addresses_of_subgroup},
substrate::{get_registered_details, get_subgroup, return_all_addresses_of_subgroup},
user::{check_in_registration_group, send_key},
validator::get_signer,
},
Expand Down Expand Up @@ -87,7 +87,11 @@ pub async fn proactive_refresh(
for key in proactive_refresh_keys {
let sig_request_address = AccountId32::from_str(&key).map_err(ProtocolErr::StringError)?;
let key_visibility =
get_key_visibility(&api, &rpc, &sig_request_address.clone().into()).await.unwrap();
get_registered_details(&api, &rpc, &sig_request_address.clone().into())
.await
.map_err(|e| ProtocolErr::UserError(e.to_string()))?
.key_visibility
.0;
if key_visibility != KeyVisibility::Public && key_visibility != KeyVisibility::Permissioned
{
return Ok(StatusCode::ACCEPTED);
Expand Down
20 changes: 10 additions & 10 deletions crypto/server/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use crate::{
launch::LATEST_BLOCK_NUMBER_NEW_USER,
signing::{create_unique_tx_id, do_signing, Hasher},
substrate::{
get_key_visibility, get_program, get_subgroup, return_all_addresses_of_subgroup,
get_program, get_registered_details, get_subgroup, return_all_addresses_of_subgroup,
},
user::{check_in_registration_group, do_dkg, send_key},
validator::get_signer,
Expand Down Expand Up @@ -106,16 +106,16 @@ pub async fn sign_tx(

let signing_address_arr: [u8; 32] = *signing_address_converted.as_ref();
let signing_address_subxt = SubxtAccountId32(signing_address_arr);
// TODO go back over to simplify accountID type
let second_signing_address_conversion = SubxtAccountId32::from_str(&signing_address)
.map_err(|_| UserErr::StringError("Account Conversion"))?;

let api = get_api(&app_state.configuration.endpoint).await?;
let rpc = get_rpc(&app_state.configuration.endpoint).await?;

let key_visibility = get_key_visibility(&api, &rpc, &second_signing_address_conversion).await?;

if key_visibility != KeyVisibility::Public && !signed_msg.verify() {
let user_details = get_registered_details(
&api,
&rpc,
&SubxtAccountId32::from(signing_address_converted.clone()),
)
.await?;
if user_details.key_visibility.0 != KeyVisibility::Public && !signed_msg.verify() {
return Err(UserErr::InvalidSignature("Invalid signature."));
}
let decrypted_message =
Expand All @@ -141,7 +141,7 @@ pub async fn sign_tx(
recover_key(&api, &rpc, &app_state.kv_store, &signer, signing_address).await?
}

let program = get_program(&api, &rpc, &second_signing_address_conversion).await?;
let program = get_program(&api, &rpc, &user_details.program_pointer).await?;

let mut runtime = Runtime::new();
let signature_request = SignatureRequest { message, auxilary_data };
Expand All @@ -158,7 +158,7 @@ pub async fn sign_tx(
&app_state,
tx_id,
signing_address_subxt,
key_visibility,
user_details.key_visibility.0,
)
.await
.map(|signature| {
Expand Down
Loading