Skip to content

Commit

Permalink
Add auxiliary data to ProgramInfo (#681)
Browse files Browse the repository at this point in the history
* add aux data to program info

* update tss

* clean

* change log

* fix

* fix registery tests

* fix

* fix

* has aux

* Apply suggestions from code review

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* clean

* fmt

* fmt

* fix

* quick fix

---------

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
  • Loading branch information
JesseAbram and HCastano authored Mar 29, 2024
1 parent e79badc commit 5a7f81e
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 87 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ At the moment this project **does not** adhere to
`registered` struct.
- In [#678](https://github.com/entropyxyz/entropy-core/pull/678), the Registry pallet's
`get_validator_info()` public method stopped returning the validator index
- In [#681](https://github.com/entropyxyz/entropy-core/pull/681) `program_interface` in
`program_data` of the `Programs` pallet has been split into `configuration_schema` and `auxiliary_data_schema`

### Added
- Add ValidatorSubgroupRotated event ([#618](https://github.com/entropyxyz/entropy-core/pull/618))
Expand All @@ -49,6 +51,7 @@ At the moment this project **does not** adhere to
- Request limit check ([#660](https://github.com/entropyxyz/entropy-core/pull/660))
- Add helper for checking if a validator is in the signing committee ([#678](https://github.com/entropyxyz/entropy-core/pull/678))
- Note unresponsiveness reports in Slashing pallet ([#679](https://github.com/entropyxyz/entropy-core/pull/679))
- Add aux data to program info ([#681](https://github.com/entropyxyz/entropy-core/pull/681))

### Changed
- Test CLI - dont send hardcoded auxiliary data by default when signing ([#614](https://github.com/entropyxyz/entropy-core/pull/614))
Expand Down
64 changes: 47 additions & 17 deletions crates/test-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ enum CliCommand {
deployer_name: String,
/// The path to a .wasm file containing the program (defaults to a test program)
program_file: Option<PathBuf>,
/// The path to a file containing the program configuration interface (defaults to empty)
program_interface_file: Option<PathBuf>,
/// The path to a file containing the program config interface (defaults to empty)
config_interface_file: Option<PathBuf>,
/// The path to a file containing the program aux interface (defaults to empty)
aux_data_interface_file: Option<PathBuf>,
},
/// Display a list of registered Entropy accounts
Status,
Expand Down Expand Up @@ -262,7 +264,12 @@ async fn run_command() -> anyhow::Result<String> {
.await?;
Ok(format!("Message signed: {:?}", recoverable_signature))
},
CliCommand::StoreProgram { deployer_name, program_file, program_interface_file } => {
CliCommand::StoreProgram {
deployer_name,
program_file,
config_interface_file,
aux_data_interface_file,
} => {
let keypair: sr25519::Pair = SeedString::new(deployer_name).try_into()?;
println!("Storing program using account: {}", keypair.public());

Expand All @@ -271,12 +278,19 @@ async fn run_command() -> anyhow::Result<String> {
None => TEST_PROGRAM_WASM_BYTECODE.to_owned(),
};

let program_interface = match program_interface_file {
let config_interface = match config_interface_file {
Some(file_name) => fs::read(file_name)?,
None => vec![],
};

let hash = store_program(&api, &rpc, &keypair, program, program_interface).await?;
let aux_data_interface = match aux_data_interface_file {
Some(file_name) => fs::read(file_name)?,
None => vec![],
};

let hash =
store_program(&api, &rpc, &keypair, program, config_interface, aux_data_interface)
.await?;
Ok(format!("Program stored {hash}"))
},
CliCommand::UpdatePrograms { signature_verifying_key, program_account_name, programs } => {
Expand Down Expand Up @@ -343,21 +357,23 @@ async fn run_command() -> anyhow::Result<String> {

if !programs.is_empty() {
println!(
"{:<11} {:<48} {:<11} {:<14} {}",
"{:<11} {:<48} {:<11} {:<14} {} {}",
"Hash".blue(),
"Stored by:".green(),
"Times used:".purple(),
"Size in bytes:".cyan(),
"Configurable?".yellow(),
"Has auxiliary?".yellow(),
);
for (hash, program_info) in programs {
println!(
"{} {} {:>11} {:>14} {}",
"{} {} {:>11} {:>14} {} {}",
hash,
program_info.deployer,
program_info.ref_counter,
program_info.bytecode.len(),
!program_info.interface_description.is_empty(),
!program_info.configuration_schema.is_empty(),
!program_info.auxiliary_data_schema.is_empty(),
);
}
}
Expand Down Expand Up @@ -451,11 +467,18 @@ impl Program {
) -> anyhow::Result<Self> {
let program_bytecode = fs::read(&filename)?;

// If there is a file with the same name with the '.interface-description' extension, read it
let interface_description = {
let mut interface_description_file = PathBuf::from(&filename);
interface_description_file.set_extension("interface-description");
fs::read(&interface_description_file).unwrap_or_default()
// If there is a file with the same name with the '.config-description' extension, read it
let config_description = {
let mut config_description_file = PathBuf::from(&filename);
config_description_file.set_extension("config-description");
fs::read(&config_description_file).unwrap_or_default()
};

// If there is a file with the same name with the '.aux-description' extension, read it
let auxiliary_data_schema = {
let mut auxiliary_data_schema_file = PathBuf::from(&filename);
auxiliary_data_schema_file.set_extension("aux-description");
fs::read(&auxiliary_data_schema_file).unwrap_or_default()
};

// If there is a file with the same name with the '.json' extension, read it
Expand All @@ -466,13 +489,20 @@ impl Program {
};

ensure!(
(interface_description.is_empty() && configuration.is_empty())
|| (!interface_description.is_empty() && !configuration.is_empty()),
(config_description.is_empty() && configuration.is_empty())
|| (!config_description.is_empty() && !configuration.is_empty()),
"If giving an interface description you must also give a configuration"
);

match store_program(api, rpc, keypair, program_bytecode.clone(), interface_description)
.await
match store_program(
api,
rpc,
keypair,
program_bytecode.clone(),
config_description,
auxiliary_data_schema,
)
.await
{
Ok(hash) => Ok(Self::new(hash, configuration)),
Err(error) => {
Expand Down
7 changes: 6 additions & 1 deletion crates/testing-utils/src/test_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,13 @@ pub async fn store_program(
deployer_pair: &sr25519::Pair,
program: Vec<u8>,
configuration_interface: Vec<u8>,
auxiliary_data_interface: Vec<u8>,
) -> anyhow::Result<<EntropyConfig as Config>::Hash> {
let update_program_tx = entropy::tx().programs().set_program(program, configuration_interface);
let update_program_tx = entropy::tx().programs().set_program(
program,
configuration_interface,
auxiliary_data_interface,
);
let deployer = PairSigner::<EntropyConfig, sr25519::Pair>::new(deployer_pair.clone());

let in_block = submit_transaction(api, rpc, &deployer, &update_program_tx, None).await?;
Expand Down
Binary file modified crates/threshold-signature-server/entropy_metadata.scale
Binary file not shown.
24 changes: 19 additions & 5 deletions crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ async fn test_sign_tx_no_chain() {
&two.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down Expand Up @@ -466,10 +467,16 @@ async fn test_program_with_config() {
let entropy_api = get_api(&substrate_context.node_proc.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.node_proc.ws_url).await.unwrap();

let program_hash =
store_program(&entropy_api, &rpc, &two.pair(), TEST_BASIC_TRANSACTION.to_owned(), vec![])
.await
.unwrap();
let program_hash = store_program(
&entropy_api,
&rpc,
&two.pair(),
TEST_BASIC_TRANSACTION.to_owned(),
vec![],
vec![],
)
.await
.unwrap();

let validators_info = vec![
ValidatorInfo {
Expand Down Expand Up @@ -569,6 +576,7 @@ async fn test_fail_signing_group() {
&eve.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down Expand Up @@ -643,6 +651,7 @@ async fn test_store_share() {
&program_manager.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down Expand Up @@ -856,6 +865,7 @@ async fn test_send_and_receive_keys() {
&program_manager.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down Expand Up @@ -1081,6 +1091,7 @@ async fn test_sign_tx_user_participates() {
&two.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down Expand Up @@ -1356,6 +1367,7 @@ async fn test_register_with_private_key_visibility() {
&program_manager.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down Expand Up @@ -1432,7 +1444,7 @@ async fn test_compute_hash() {

let mut runtime = Runtime::default();
let program_hash =
store_program(&api, &rpc, &one.pair(), TEST_PROGRAM_CUSTOM_HASH.to_owned(), vec![])
store_program(&api, &rpc, &one.pair(), TEST_PROGRAM_CUSTOM_HASH.to_owned(), vec![], vec![])
.await
.unwrap();

Expand Down Expand Up @@ -1508,6 +1520,7 @@ async fn test_fail_infinite_program() {
&two.pair(),
TEST_INFINITE_LOOP_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down Expand Up @@ -1586,6 +1599,7 @@ async fn test_mutiple_confirm_done() {
&program_manager.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down
15 changes: 11 additions & 4 deletions crates/threshold-signature-server/tests/protocol_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ async fn test_wasm_sign_tx_user_participates() {
&dave.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down Expand Up @@ -220,10 +221,16 @@ async fn test_wasm_register_with_private_key_visibility() {
let substrate_context = test_context_stationary().await;
let api = get_api(&substrate_context.node_proc.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.node_proc.ws_url).await.unwrap();
let program_pointer =
store_program(&api, &rpc, &dave.pair(), TEST_PROGRAM_WASM_BYTECODE.to_owned(), vec![])
.await
.unwrap();
let program_pointer = store_program(
&api,
&rpc,
&dave.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();

let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1;

Expand Down
2 changes: 2 additions & 0 deletions crates/threshold-signature-server/tests/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async fn integration_test_sign_public() {
&deployer.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down Expand Up @@ -114,6 +115,7 @@ async fn integration_test_sign_private() {
&deployer.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/threshold-signature-server/tests/sign_eth_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async fn integration_test_sign_eth_tx() {
&deployer.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
)
.await
.unwrap();
Expand Down
19 changes: 12 additions & 7 deletions pallets/programs/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ benchmarks! {

set_program {
let program = vec![10];
let interface_description = vec![11];
let configuration_schema = vec![11];
let auxiliary_data_schema = vec![12];
let mut hash_input: Vec<u8> = vec![];
hash_input.extend(&program);
hash_input.extend(&interface_description);
hash_input.extend(&configuration_schema);
hash_input.extend(&auxiliary_data_schema);

let program_hash = T::Hashing::hash(&hash_input);
let deployer: T::AccountId = whitelisted_caller();
Expand All @@ -54,24 +56,27 @@ benchmarks! {
let value = CurrencyOf::<T>::minimum_balance().saturating_mul(1_000_000_000u32.into());
let _ = CurrencyOf::<T>::make_free_balance_be(&deployer, value);

}: _(RawOrigin::Signed(deployer.clone()), program.clone(), interface_description.clone())
}: _(RawOrigin::Signed(deployer.clone()), program.clone(), configuration_schema.clone(), auxiliary_data_schema.clone())
verify {
assert_last_event::<T>(
Event::<T>::ProgramCreated {
deployer,
program_hash,
interface_description
configuration_schema,
auxiliary_data_schema
}.into()
);
}

remove_program {
let p in 0..T::MaxOwnedPrograms::get();
let program = vec![10];
let interface_description = vec![11];
let configuration_schema = vec![11];
let auxiliary_data_schema = vec![12];
let mut hash_input: Vec<u8> = vec![];
hash_input.extend(&program);
hash_input.extend(&interface_description);
hash_input.extend(&configuration_schema);
hash_input.extend(&auxiliary_data_schema);

let program_hash = T::Hashing::hash(&hash_input);
let random_program = vec![11];
Expand All @@ -80,7 +85,7 @@ benchmarks! {

let value = CurrencyOf::<T>::minimum_balance().saturating_mul(1_000_000_000u32.into());
let _ = CurrencyOf::<T>::make_free_balance_be(&deployer, value);
<Programs<T>>::insert(program_hash.clone(), ProgramInfo {bytecode: program, interface_description, deployer: deployer.clone(), ref_counter: 0u128});
<Programs<T>>::insert(program_hash.clone(), ProgramInfo {bytecode: program, configuration_schema, auxiliary_data_schema, deployer: deployer.clone(), ref_counter: 0u128});
let mut program_hashes = vec![random_hash.clone(); p as usize];
// remove one to make room for the targetted removal program hash
program_hashes.pop();
Expand Down
Loading

0 comments on commit 5a7f81e

Please sign in to comment.