-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sequence number for replay protection (#252)
- Loading branch information
Showing
17 changed files
with
171 additions
and
198 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod attested; | ||
pub mod sequenced; | ||
pub mod session_create; | ||
pub mod session_set_pub_key; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response, StdResult, Uint64}; | ||
|
||
use crate::{ | ||
error::Error, handler::Handler, msg::execute::sequenced::SequencedMsg, state::SEQUENCE_NUM, | ||
}; | ||
|
||
impl<T: Handler> Handler for SequencedMsg<T> { | ||
fn handle(self, deps: DepsMut<'_>, env: &Env, info: &MessageInfo) -> Result<Response, Error> { | ||
SEQUENCE_NUM.update(deps.storage, |mut counter| -> StdResult<_> { | ||
counter += Uint64::one(); | ||
Ok(counter) | ||
})?; | ||
|
||
self.0.handle(deps, env, info) | ||
} | ||
} |
15 changes: 11 additions & 4 deletions
15
crates/contracts/core/src/handler/execute/session_set_pub_key.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod attested; | ||
pub mod sequenced; | ||
pub mod session_create; | ||
pub mod session_set_pub_key; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use cosmwasm_schema::cw_serde; | ||
use cosmwasm_std::StdError; | ||
use serde::Serialize; | ||
|
||
use crate::msg::HasDomainType; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct SequencedMsg<D>(pub D); | ||
|
||
#[cw_serde] | ||
pub struct RawSequencedMsg<R>(pub R); | ||
|
||
impl<R: Serialize + HasDomainType> HasDomainType for RawSequencedMsg<R> { | ||
type DomainType = SequencedMsg<R::DomainType>; | ||
} | ||
|
||
impl<R: HasDomainType> TryFrom<RawSequencedMsg<R>> for SequencedMsg<R::DomainType> { | ||
type Error = StdError; | ||
|
||
fn try_from(value: RawSequencedMsg<R>) -> Result<Self, Self::Error> { | ||
Ok(Self(value.0.try_into()?)) | ||
} | ||
} | ||
|
||
impl<R: HasDomainType> From<SequencedMsg<R::DomainType>> for RawSequencedMsg<R> { | ||
fn from(value: SequencedMsg<R::DomainType>) -> Self { | ||
Self(value.0.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.