Skip to content

Commit

Permalink
chore: add admin check to native token minter
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <abdullaheryz@protonmail.com>
  • Loading branch information
aeryz committed Jan 25, 2025
1 parent 9d7a5d6 commit f773b97
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 20 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ members = [
"lib/ibc-classic-spec",
"lib/state-lens-light-client-types",
"lib/create3",
"lib/linea-types", "cosmwasm/native-token-minter", "cosmwasm/cw20-token-minter", "cosmwasm/ucs03-zkgm-token-minter-api",
"lib/linea-types",
"cosmwasm/native-token-minter",
"cosmwasm/cw20-token-minter",
"cosmwasm/ucs03-zkgm-token-minter-api",
]

[workspace.package]
Expand Down Expand Up @@ -244,7 +247,7 @@ ibc-union = { path = "cosmwasm/ibc-union/core", default-features =
ibc-union-light-client = { path = "cosmwasm/ibc-union/core/light-client-interface", default-features = false }
ibc-union-msg = { path = "cosmwasm/ibc-union/core/msg", default-features = false }

ucs03-zkgm-token-minter-api = { path = "cosmwasm/ucs03-zkgm-token-minter-api", default-features = false }
ucs03-zkgm-token-minter-api = { path = "cosmwasm/ucs03-zkgm-token-minter-api", default-features = false }

gnark-key-parser = { path = "lib/gnark-key-parser", default-features = false }
gnark-mimc = { path = "lib/gnark-mimc", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/cw20-token-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmwasm_std::{
MessageInfo, Reply, ReplyOn, Response, StdResult, SubMsg, WasmMsg,
};
use token_factory_api::TokenFactoryMsg;
use ucs03_zkgm_msg::{ExecuteMsg, LocalTokenMsg};
use ucs03_zkgm_token_minter_api::{ExecuteMsg, LocalTokenMsg};

use crate::{
error::Error,
Expand Down
2 changes: 2 additions & 0 deletions cosmwasm/native-token-minter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ version = "0.0.0"
[dependencies]
cosmwasm-schema = { version = "1.5" }
cosmwasm-std = { version = "1.5" }
cw-storage-plus = { version = "1.2" }
thiserror = { workspace = true }
token-factory-api = { workspace = true }
ucs03-zkgm-token-minter-api = { workspace = true }

Expand Down
30 changes: 22 additions & 8 deletions cosmwasm/native-token-minter/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{
entry_point, BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response, StdResult,
entry_point, Addr, BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response, StdResult,
};
use token_factory_api::TokenFactoryMsg;
use ucs03_zkgm_token_minter_api::{ExecuteMsg, LocalTokenMsg};

use crate::{error::Error, state::ADMIN};

#[cw_serde]
pub struct InitMsg {}
pub struct InitMsg {
admin: Addr,
}

#[entry_point]
pub fn instantiate(
_deps: DepsMut,
deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: InitMsg,
msg: InitMsg,
) -> StdResult<Response> {
ADMIN.save(deps.storage, &msg.admin)?;
Ok(Response::default())
}

Expand All @@ -28,11 +33,17 @@ pub fn migrate(_: DepsMut, _: Env, _: MigrateMsg) -> StdResult<Response> {

#[entry_point]
pub fn execute(
_deps: DepsMut,
deps: DepsMut,
_env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> StdResult<Response<TokenFactoryMsg>> {
) -> Result<Response<TokenFactoryMsg>, Error> {
let admin = ADMIN.load(deps.storage)?;

if admin != info.sender {
return Err(Error::OnlyAdmin);
}

let resp = match msg {
ExecuteMsg::Wrapped(msg) => {
if let TokenFactoryMsg::BurnTokens { denom, amount, .. } = &msg {
Expand All @@ -41,7 +52,10 @@ pub fn execute(
.iter()
.any(|coin| &coin.denom == denom && &coin.amount == amount);
if !contains_base_token {
panic!("missing funds");
return Err(Error::MissingFunds {
denom: denom.clone(),
amount: amount.clone(),
});
}
}
Response::new().add_message(CosmosMsg::Custom(msg))
Expand All @@ -53,7 +67,7 @@ pub fn execute(
.iter()
.any(|coin| coin.denom == denom && coin.amount == amount);
if !contains_base_token {
panic!("missing funds");
return Err(Error::MissingFunds { denom, amount });
}
Response::new()
}
Expand Down
13 changes: 13 additions & 0 deletions cosmwasm/native-token-minter/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use cosmwasm_std::{StdError, Uint128};

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
StdError(#[from] StdError),

#[error("only the admin can execute")]
OnlyAdmin,

#[error("missing funds for denom {denom} with amount {amount}")]
MissingFunds { denom: String, amount: Uint128 },
}
2 changes: 2 additions & 0 deletions cosmwasm/native-token-minter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pub mod contract;
pub mod error;
pub mod state;
4 changes: 4 additions & 0 deletions cosmwasm/native-token-minter/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use cosmwasm_std::Addr;
use cw_storage_plus::Item;

pub const ADMIN: Item<Addr> = Item::new("admin");
18 changes: 9 additions & 9 deletions cosmwasm/ucs03-zkgm-token-minter-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "ucs03-zkgm-token-minter-api"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
authors.workspace = true
edition.workspace = true
license-file.workspace = true
publish.workspace = true
repository.workspace = true
name = "ucs03-zkgm-token-minter-api"
publish.workspace = true
repository.workspace = true
version = "0.1.0"

[dependencies]
cosmwasm-schema = { version = "1.5" }
cosmwasm-std = { version = "1.5" }
enumorph = { workspace = true }
token-factory-api = { workspace = true }
cosmwasm-std = { version = "1.5" }
cosmwasm-schema = { version = "1.5" }
enumorph = { workspace = true }

[lints]
workspace = true

0 comments on commit f773b97

Please sign in to comment.