diff --git a/vm/templates/multisig/elf/multisig b/vm/templates/multisig/elf/multisig index 69c71e93cb..52a867d0f1 100755 --- a/vm/templates/multisig/elf/multisig +++ b/vm/templates/multisig/elf/multisig @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:88ac5b547e32b2f16d2e86701d31e09b68d036fab690bfb04a964e0b0d6c2abc +oid sha256:e4ec42b1099be6ae47030eefee99e0bb6b933e962f68ea40b2a73c35797e3c0f size 50792 diff --git a/vm/templates/multisig/src/contract.rs b/vm/templates/multisig/src/contract.rs index 61943b211a..8ce0ebd621 100644 --- a/vm/templates/multisig/src/contract.rs +++ b/vm/templates/multisig/src/contract.rs @@ -1,5 +1,4 @@ //! The Spacemesh standard multi-signature wallet template. -extern crate alloc; use athena_interface::Address; use athena_vm_declare::{callable, template}; @@ -10,25 +9,13 @@ use parity_scale_codec::{Decode, Encode, IoReader}; #[derive(Encode, Decode)] struct Contract { required: u8, - keys: alloc::vec::Vec, -} - -#[derive(Decode)] -struct SpawnArguments { - required: u8, - keys: alloc::vec::Vec, -} - -#[derive(Encode, Decode)] -struct Signature { - id: u8, - sig: [u8; 64], + keys: Vec, } #[template] impl Contract { #[callable] - fn spawn(args: SpawnArguments) -> Address { + fn spawn(args: multisig::SpawnArguments) -> Address { let wallet = Contract { required: args.required, keys: args.keys, @@ -43,7 +30,7 @@ impl Contract { } #[callable] - fn deploy(&self, code: alloc::vec::Vec) -> Address { + fn deploy(&self, code: Vec) -> Address { athena_vm_sdk::deploy(&code) } @@ -56,11 +43,11 @@ impl Contract { fn verify() -> bool { let mut io = IoReader(athena_vm::io::Io::default()); let state = Contract::decode(&mut io).unwrap(); - let tx = alloc::vec::Vec::::decode(&mut io).unwrap(); + let tx = Vec::::decode(&mut io).unwrap(); let mut last_id = None; for _ in 0..state.required { - let sig = if let Ok(s) = Signature::decode(&mut io) { + let sig = if let Ok(s) = multisig::Signature::decode(&mut io) { s } else { return false; diff --git a/vm/templates/multisig/src/lib.rs b/vm/templates/multisig/src/lib.rs new file mode 100644 index 0000000000..8a1321f701 --- /dev/null +++ b/vm/templates/multisig/src/lib.rs @@ -0,0 +1,14 @@ +use athena_vm_sdk::Pubkey; +use parity_scale_codec::{Decode, Encode}; + +#[derive(Encode, Decode)] +pub struct SpawnArguments { + pub required: u8, + pub keys: Vec, +} + +#[derive(Encode, Decode)] +pub struct Signature { + pub id: u8, + pub sig: [u8; 64], +} diff --git a/vm/templates/multisig/tests/test.rs b/vm/templates/multisig/tests/test.rs index 4694bafdec..93b7811490 100644 --- a/vm/templates/multisig/tests/test.rs +++ b/vm/templates/multisig/tests/test.rs @@ -1,8 +1,9 @@ use std::error::Error; use athena_interface::{Address, MethodSelector}; -use athena_sdk::{AthenaStdin, ExecutionClient}; +use athena_sdk::{host::MockHostInterface, AthenaStdin, ExecutionClient}; use athena_vm_sdk::Pubkey; +use multisig::SpawnArguments; use parity_scale_codec::Encode; use ed25519_dalek::ed25519::signature::Signer; @@ -11,12 +12,6 @@ use rand::rngs::OsRng; pub const PROGRAM: &[u8] = include_bytes!("../elf/multisig"); pub const ADDRESS_ALICE: [u8; 24] = [1u8; 24]; -#[derive(Encode)] -struct SpawnArguments { - required: u8, - keys: Vec, -} - #[derive(Clone)] struct SigningKey { id: u8, @@ -26,7 +21,7 @@ struct SigningKey { fn spawn(required: u8, keys: Vec) -> Result<(Address, Vec), Box> { let mut stdin = AthenaStdin::new(); let (state_w, state_r) = std::sync::mpsc::channel(); - let mut host = athena_interface::MockHostInterface::new(); + let mut host = MockHostInterface::new(); host.expect_spawn().returning_st(move |s| { state_w.send(s).unwrap(); Address::from(ADDRESS_ALICE) @@ -48,7 +43,8 @@ fn spawn(required: u8, keys: Vec) -> Result<(Address, Vec), Box, keys: &[SigningKey]) -> bool { @@ -59,9 +55,11 @@ fn verify(state: Vec, keys: &[SigningKey]) -> bool { stdin.write_vec(tx.as_slice().encode()); for key in keys.iter() { - let signature = key.key.sign(tx); - stdin.write_vec(key.id.encode()); - stdin.write_vec(signature.to_bytes().encode()); + let signature = multisig::Signature { + id: key.id, + sig: key.key.sign(tx).to_bytes(), + }; + stdin.write_vec(signature.encode()); } let result = ExecutionClient::new().execute_function(