Skip to content

Commit

Permalink
fix misc
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Dec 14, 2023
1 parent f79bdca commit 1e0c373
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
10 changes: 5 additions & 5 deletions modules/commitments/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ define_error! {
format_args!("invalid bytes length: expected=0or{} actual={}", e.expected, e.actual)
},

UnexpectedCommitmentType
UnexpectedMessageType
{
expected: u16,
actual: u16
}
|e| {
format_args!("unexpected commitment type: expected={} actual={}", e.expected, e.actual)
format_args!("unexpected message type: expected={} actual={}", e.expected, e.actual)
},

InvalidCommitmentHeader
InvalidMessageHeader
{
descr: String
}
|e| {
format_args!("invalid commitment header: descr={}", e.descr)
format_args!("invalid message header: descr={}", e.descr)
},

InvalidValidationContextHeader
{
descr: String
}
|e| {
format_args!("invalid commitment context header: descr={}", e.descr)
format_args!("invalid validation context header: descr={}", e.descr)
},

OutOfTrustingPeriod
Expand Down
48 changes: 24 additions & 24 deletions modules/commitments/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ impl Message {

// MSB first
// 0-1: version
// 2-3: commitment type
// 2-3: message type
// 4-31: reserved
pub fn header(&self) -> [u8; MESSAGE_HEADER_SIZE] {
let mut header = [0u8; MESSAGE_HEADER_SIZE];
header[0..=1].copy_from_slice(&MESSAGE_SCHEMA_VERSION.to_be_bytes());
header[2..=3].copy_from_slice(&self.commitment_type().to_be_bytes());
header[2..=3].copy_from_slice(&self.message_type().to_be_bytes());
header
}

pub fn commitment_type(&self) -> u16 {
pub fn message_type(&self) -> u16 {
match self {
Message::UpdateClient(_) => MESSAGE_TYPE_UPDATE_CLIENT,
Message::VerifyMembership(_) => MESSAGE_TYPE_STATE,
Expand All @@ -61,9 +61,9 @@ impl TryFrom<Message> for UpdateClientMessage {
fn try_from(value: Message) -> Result<Self, Self::Error> {
match value {
Message::UpdateClient(m) => Ok(m),
_ => Err(Error::unexpected_commitment_type(
_ => Err(Error::unexpected_message_type(
MESSAGE_TYPE_UPDATE_CLIENT,
value.commitment_type(),
value.message_type(),
)),
}
}
Expand All @@ -74,9 +74,9 @@ impl TryFrom<Message> for VerifyMembershipMessage {
fn try_from(value: Message) -> Result<Self, Self::Error> {
match value {
Message::VerifyMembership(m) => Ok(m),
_ => Err(Error::unexpected_commitment_type(
_ => Err(Error::unexpected_message_type(
MESSAGE_TYPE_STATE,
value.commitment_type(),
value.message_type(),
)),
}
}
Expand Down Expand Up @@ -147,14 +147,14 @@ impl EthABIEncoder for Message {
}

fn ethabi_decode(bz: &[u8]) -> Result<Self, Error> {
let eth_abi_commitment = EthABIHeaderedMessage::decode(bz)?;
let (version, commitment_type) = {
let header = &eth_abi_commitment.header;
let eth_abi_message = EthABIHeaderedMessage::decode(bz)?;
let (version, message_type) = {
let header = &eth_abi_message.header;
if header.len() != MESSAGE_HEADER_SIZE {
return Err(Error::invalid_commitment_header(format!(
return Err(Error::invalid_message_header(format!(
"invalid header length: expected={MESSAGE_HEADER_SIZE} actual={} header={:?}",
header.len(),
eth_abi_commitment.header
eth_abi_message.header
)));
}
let mut version = [0u8; 2];
Expand All @@ -167,18 +167,18 @@ impl EthABIEncoder for Message {
)
};
if version != MESSAGE_SCHEMA_VERSION {
return Err(Error::invalid_commitment_header(format!(
return Err(Error::invalid_message_header(format!(
"invalid version: expected={} actual={} header={:?}",
MESSAGE_SCHEMA_VERSION, version, eth_abi_commitment.header
MESSAGE_SCHEMA_VERSION, version, eth_abi_message.header
)));
}
let message = eth_abi_commitment.message;
match commitment_type {
let message = eth_abi_message.message;
match message_type {
MESSAGE_TYPE_UPDATE_CLIENT => Ok(UpdateClientMessage::ethabi_decode(&message)?.into()),
MESSAGE_TYPE_STATE => Ok(VerifyMembershipMessage::ethabi_decode(&message)?.into()),
_ => Err(Error::invalid_abi(format!(
"invalid commitment type: {}",
commitment_type
"invalid message type: {}",
message_type
))),
}
}
Expand Down Expand Up @@ -210,7 +210,7 @@ mod tests {
Height::new(tuple.0, tuple.1)
}

fn test_update_client_commitment(
fn test_update_client_message(
c1: UpdateClientMessage,
proof_signer: Address,
proof_signature: Vec<u8>,
Expand All @@ -232,7 +232,7 @@ mod tests {

proptest! {
#[test]
fn pt_update_client_commitment_with_empty_context(
fn pt_update_client_message_with_empty_context(
prev_height in any::<Option<(u64, u64)>>().prop_map(|v| v.map(height_from_tuple)),
prev_state_id in any::<Option<[u8; 32]>>().prop_map(|v| v.map(StateID::from)),
post_height in any::<(u64, u64)>().prop_map(height_from_tuple),
Expand All @@ -253,11 +253,11 @@ mod tests {
timestamp: Time::from_unix_timestamp_nanos(timestamp).unwrap(),
context: Default::default(),
};
test_update_client_commitment(c1, Address(proof_signer), proof_signature.to_vec());
test_update_client_message(c1, Address(proof_signer), proof_signature.to_vec());
}

#[test]
fn pt_update_client_commitment_with_trusting_period_context(
fn pt_update_client_message_with_trusting_period_context(
prev_height in any::<Option<(u64, u64)>>().prop_map(|v| v.map(height_from_tuple)),
prev_state_id in any::<Option<[u8; 32]>>().prop_map(|v| v.map(StateID::from)),
post_height in any::<(u64, u64)>().prop_map(height_from_tuple),
Expand Down Expand Up @@ -287,11 +287,11 @@ mod tests {
Time::from_unix_timestamp_nanos(trusted_state_timestamp).unwrap(),
).into(),
};
test_update_client_commitment(c1, Address(proof_signer), proof_signature.to_vec());
test_update_client_message(c1, Address(proof_signer), proof_signature.to_vec());
}

#[test]
fn pt_state_commitment(
fn pt_verify_membership(
prefix in any::<CommitmentPrefix>(),
path in any::<String>(),
value in any::<Option<[u8; 32]>>(),
Expand Down
4 changes: 2 additions & 2 deletions modules/enclave-api/src/api/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub trait EnclaveCommandAPI<S: CommitStore>: EnclavePrimitiveAPI<S> {
}
}

/// verify_membership verifies the existence of the state in the upstream chain and generates the state commitment of its result
/// verify_membership verifies the existence of the state in the upstream chain and generates a message that represents membership of value in the state
fn verify_membership(&self, input: VerifyMembershipInput) -> Result<VerifyMembershipResult> {
match self.execute_command(
Command::LightClient(LightClientCommand::Execute(
Expand All @@ -122,7 +122,7 @@ pub trait EnclaveCommandAPI<S: CommitStore>: EnclavePrimitiveAPI<S> {
}
}

/// verify_non_membership verifies the non-existence of the state in the upstream chain and generates the state commitment of its result
/// verify_non_membership verifies the non-existence of the state in the upstream chain and generates a message that represents non-membership of value in the state
fn verify_non_membership(
&self,
input: VerifyNonMembershipInput,
Expand Down
2 changes: 1 addition & 1 deletion modules/lcp-client/src/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ mod tests {
res.unwrap()
};

// 5. on the downstream side, updates LCP Light Client's state with the commitment from the LCP
// 5. on the downstream side, updates LCP Light Client's state with the message from the ELC
{
let header = ClientMessage::UpdateClient(UpdateClientMessage {
elc_message: proof1.message().unwrap().try_into().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions modules/light-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ pub struct UpdateClientResult {

#[derive(Clone, Debug, PartialEq)]
pub struct VerifyMembershipResult {
/// state commitment represents a result of the state verification
/// message represents a result of the state verification
pub message: Message,
}

#[derive(Clone, Debug, PartialEq)]
pub struct VerifyNonMembershipResult {
/// state commitment represents a result of the state verification
/// message represents a result of the state verification
pub message: Message,
}

0 comments on commit 1e0c373

Please sign in to comment.