diff --git a/ampd/src/stacks/its_verifier.rs b/ampd/src/stacks/its_verifier.rs index b6e15c626..7dfc4eb1f 100644 --- a/ampd/src/stacks/its_verifier.rs +++ b/ampd/src/stacks/its_verifier.rs @@ -8,6 +8,11 @@ use crate::stacks::error::Error; use crate::stacks::http_client::TransactionEvents; use crate::stacks::verifier::{CONTRACT_CALL_TYPE, PRINT_TOPIC}; +const MESSAGE_TYPE_INTERCHAIN_TRANSFER: u128 = 0; +const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN: u128 = 1; +const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER: u128 = 2; +const MESSAGE_TYPE_SEND_TO_HUB: u128 = 3; + impl Message { pub fn eq_its_hub_event( &self, @@ -20,13 +25,7 @@ impl Message { } let tuple_type_signature = TupleTypeSignature::try_from(vec![ - ( - ClarityName::from("type"), - TypeSignature::SequenceType(SequenceSubtype::StringType(StringSubtype::ASCII( - BufferLength::try_from(13u32)?, - ))), - ), - (ClarityName::from("sender"), TypeSignature::PrincipalType), + (ClarityName::from("type"), TypeSignature::UIntType), ( ClarityName::from("destination-chain"), TypeSignature::SequenceType(SequenceSubtype::BufferType(BufferLength::try_from( @@ -34,15 +33,9 @@ impl Message { )?)), ), ( - ClarityName::from("destination-contract-address"), - TypeSignature::SequenceType(SequenceSubtype::BufferType(BufferLength::try_from( - 96u32, - )?)), - ), - ( - ClarityName::from("payload-hash"), + ClarityName::from("payload"), TypeSignature::SequenceType(SequenceSubtype::BufferType(BufferLength::try_from( - 32u32, + 10240u32, )?)), ), ])?; @@ -57,41 +50,34 @@ impl Message { Value::try_deserialize_hex(hex, &TypeSignature::TupleType(tuple_type_signature), true)?; if let Value::Tuple(data) = value { - if !data.get("type")?.eq(&Value::string_ascii_from_bytes( - CONTRACT_CALL_TYPE.as_bytes().to_vec(), - )?) { - return Ok(false); - } - - if !data.get("sender")?.eq(&Value::from(PrincipalData::parse( - self.source_address.as_str(), - )?)) { - return Ok(false); - } - - if !data.get("destination-chain")?.eq(&Value::buff_from( - self.destination_chain.as_ref().as_bytes().to_vec(), - )?) { - return Ok(false); - } - - if !data - .get("destination-contract-address")? - .eq(&Value::buff_from( - self.destination_address.as_bytes().to_vec(), - )?) - { + // All messages should go through ITS hub + if !data.get("type")?.eq(&Value::UInt(MESSAGE_TYPE_SEND_TO_HUB)) { return Ok(false); } - if !data - .get("payload-hash")? - .eq(&Value::buff_from(self.payload_hash.as_bytes().to_vec())?) - { - return Ok(false); + let subtuple_type_signature = TupleTypeSignature::try_from(vec![( + ClarityName::from("type"), + TypeSignature::UIntType, + )])?; + + let original_value = Value::try_deserialize_hex( + hex, + &TypeSignature::TupleType(subtuple_type_signature), + true, + )?; + + // Unwrapp its payload + if let Value::Tuple(new_data) = original_value { + if new_data.get("type")?.eq(&Value::UInt(MESSAGE_TYPE_INTERCHAIN_TRANSFER)) { + // TODO: Decode and ABI encode this payload + } else if new_data.get("type")?.eq(&Value::UInt(MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN)) { + // TODO: Decode and ABI encode this payload + } else if new_data.get("type")?.eq(&Value::UInt(MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER)) { + // TODO: Decode and ABI encode this payload + } } - return Ok(true); + return Ok(false); } Ok(false) diff --git a/ampd/src/stacks/verifier.rs b/ampd/src/stacks/verifier.rs index 1985c5a06..d04e16be7 100644 --- a/ampd/src/stacks/verifier.rs +++ b/ampd/src/stacks/verifier.rs @@ -191,30 +191,28 @@ pub fn verify_message( match find_event(transaction, gateway_address, message.event_index) { Some(event) => { - // In case message is from its - if &message.source_address == its_address { - // In case messages is from Stacks -> Stacks and from ITS -> ITS, use custom logic - if &message.destination_chain == source_chain - && &message.destination_address == its_address - { - if message.eq_its_verify_event(event).unwrap_or(false) { - return Vote::SucceededOnChain; - } - - return Vote::NotFound; + // In case message is not from ITS + if &message.source_address != its_address { + if message.eq_event(event).unwrap_or(false) { + return Vote::SucceededOnChain; } - // TODO: Should we check if the message is towards axelar and ITS Hub contract here? - // In other case, abi encode payload + return Vote::NotFound; + } - if message.eq_its_hub_event(event).unwrap_or(false) { + // In case messages is from Stacks -> Stacks and from ITS -> ITS, use custom logic + if &message.destination_chain == source_chain + && &message.destination_address == its_address + { + if message.eq_its_verify_event(event).unwrap_or(false) { return Vote::SucceededOnChain; } return Vote::NotFound; } - if message.eq_event(event).unwrap_or(false) { + // In other case, abi encode payload coming from Stacks ITS + if message.eq_its_hub_event(event).unwrap_or(false) { return Vote::SucceededOnChain; }