Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify clock is the caller #32

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion contracts/clock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
neutron-sdk = { workspace = true }

[dev-dependencies]
cw-multi-test = { workspace = true }
anyhow = { workspace = true }
anyhow = { workspace = true }
12 changes: 11 additions & 1 deletion contracts/clock/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use cosmwasm_std::StdError;
use neutron_sdk::NeutronError;
use thiserror::Error;

#[derive(Error, Debug)]
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error(transparent)]
Std(#[from] StdError),
Expand All @@ -23,4 +24,13 @@ pub enum ContractError {

#[error("only contracts may be enqueued. error reading contract info: ({0})")]
NotContract(String),

#[error("Caller is not the clock, only clock can tick contracts")]
NotClock,
}

impl Into<NeutronError> for ContractError {
fn into(self) -> NeutronError {
NeutronError::Std(StdError::generic_err(self.to_string()))
}
}
13 changes: 11 additions & 2 deletions contracts/clock/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::msg::ExecuteMsg::{Dequeue, Enqueue};
use cosmwasm_std::{to_binary, StdResult, WasmMsg};
use crate::{msg::ExecuteMsg::{Dequeue, Enqueue}, error::ContractError};
use cosmwasm_std::{to_binary, StdResult, WasmMsg, Addr};
use neutron_sdk::NeutronError;

pub fn enqueue_msg(addr: &str) -> StdResult<WasmMsg> {
Ok(WasmMsg::Execute {
Expand All @@ -16,3 +17,11 @@ pub fn dequeue_msg(addr: &str) -> StdResult<WasmMsg> {
funds: vec![],
})
}

pub fn verify_clock(caller: Addr, clock_addr: Addr) -> Result<(), ContractError>{
if caller != clock_addr {
return Err(ContractError::NotClock)
}

Ok(())
}
21 changes: 13 additions & 8 deletions contracts/depositor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ use crate::state::{
save_reply_payload, save_sudo_payload, AcknowledgementResult, ContractState, SudoPayload,
ACKNOWLEDGEMENT_RESULTS, CLOCK_ADDRESS, CONTRACT_STATE, GAIA_NEUTRON_IBC_TRANSFER_CHANNEL_ID,
GAIA_STRIDE_IBC_TRANSFER_CHANNEL_ID, IBC_PORT_ID, ICA_ADDRESS, INTERCHAIN_ACCOUNTS, LP_ADDRESS,
NATIVE_ATOM_RECEIVER, NEUTRON_GAIA_CONNECTION_ID, STRIDE_ATOM_RECEIVER, SUDO_PAYLOAD_REPLY_ID, LS_ADDRESS,
LS_ADDRESS, NATIVE_ATOM_RECEIVER, NEUTRON_GAIA_CONNECTION_ID, STRIDE_ATOM_RECEIVER,
SUDO_PAYLOAD_REPLY_ID,
};

// Default timeout for SubmitTX is two weeks
Expand Down Expand Up @@ -82,9 +83,10 @@ pub fn instantiate(
GAIA_NEUTRON_IBC_TRANSFER_CHANNEL_ID
.save(deps.storage, &msg.gaia_neutron_ibc_transfer_channel_id)?;
NEUTRON_GAIA_CONNECTION_ID.save(deps.storage, &msg.neutron_gaia_connection_id)?;
GAIA_STRIDE_IBC_TRANSFER_CHANNEL_ID.save(deps.storage, &msg.gaia_stride_ibc_transfer_channel_id)?;
GAIA_STRIDE_IBC_TRANSFER_CHANNEL_ID
.save(deps.storage, &msg.gaia_stride_ibc_transfer_channel_id)?;
LS_ADDRESS.save(deps.storage, &msg.ls_address)?;

GAIA_STRIDE_IBC_TRANSFER_CHANNEL_ID
.save(deps.storage, &msg.gaia_stride_ibc_transfer_channel_id)?;

Expand All @@ -107,13 +109,17 @@ pub fn execute(
}

fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult<Response<NeutronMsg>> {
// Verify caller is the clock
if info.sender != CLOCK_ADDRESS.load(deps.storage)? {
return Err(covenant_clock::error::ContractError::NotClock.into());
}

let current_state = CONTRACT_STATE.load(deps.storage)?;
let ica_address: Result<String, StdError> = ICA_ADDRESS.load(deps.storage);
let gaia_account_address = match ica_address {
Ok(addr) => addr,
Err(_) => "todo".to_string(),
};
// TODO: validate caller is clock, do we really care its the clock?

match current_state {
ContractState::Instantiated => try_register_gaia_ica(deps, env),
Expand All @@ -133,10 +139,9 @@ fn try_liquid_stake(
) -> NeutronResult<Response<NeutronMsg>> {
let ls_address = LS_ADDRESS.load(deps.storage)?;

let stride_ica_query: Option<String> = deps.querier.query_wasm_smart(
ls_address,
&covenant_ls::msg::QueryMsg::StrideICA { }
)?;
let stride_ica_query: Option<String> = deps
.querier
.query_wasm_smart(ls_address, &covenant_ls::msg::QueryMsg::StrideICA {})?;
let stride_ica_addr = match stride_ica_query {
Some(addr) => addr,
None => return Err(NeutronError::Std(StdError::not_found("no ica found"))),
Expand Down
5 changes: 5 additions & 0 deletions contracts/lper/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ pub fn execute(


fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult<Response<NeutronMsg>> {
// Verify caller is the clock
if info.sender != CLOCK_ADDRESS.load(deps.storage)? {
return Err(covenant_clock::error::ContractError::NotClock.into());
}

let current_state = CONTRACT_STATE.load(deps.storage)?;

match current_state {
Expand Down
14 changes: 8 additions & 6 deletions contracts/ls/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use cosmos_sdk_proto::traits::Message;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Addr, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, MessageInfo, Reply,
Response, StdError, StdResult, SubMsg, Uint128,
to_binary, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Env, MessageInfo, Reply, Response,
StdError, StdResult, SubMsg, Uint128,
};
use cw2::set_contract_version;
use neutron_sdk::bindings::msg::IbcFee;
Expand Down Expand Up @@ -100,13 +100,17 @@ pub fn execute(
}

fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult<Response<NeutronMsg>> {
// Verify caller is the clock
if info.sender != CLOCK_ADDRESS.load(deps.storage)? {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the verify_clock here from clock helpers?

return Err(covenant_clock::error::ContractError::NotClock.into());
}

let current_state = CONTRACT_STATE.load(deps.storage)?;
let ica_address: Result<String, StdError> = ICA_ADDRESS.load(deps.storage);
let gaia_account_address = match ica_address {
Ok(addr) => addr,
Err(_) => "todo".to_string(),
};
// TODO: validate caller is clock

match current_state {
ContractState::Instantiated => try_register_stride_ica(deps, env),
Expand Down Expand Up @@ -245,9 +249,7 @@ pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> NeutronResult
interchain_account_id,
connection_id,
} => query_interchain_address(deps, env, interchain_account_id, connection_id),
QueryMsg::StrideICA {} => Ok(
to_binary(&ICA_ADDRESS.may_load(deps.storage)?)?
)
QueryMsg::StrideICA {} => Ok(to_binary(&ICA_ADDRESS.may_load(deps.storage)?)?),
}
}

Expand Down