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

Neutron audit informal 04 09 2023 fixes #84

Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 10 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/dao/cwd-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "A DAO DAO core module."
edition = "2021"
name = "cwd-core"
repository = "https://github.com/DA0-DA0/dao-contracts"
version = "0.2.0"
version = "0.2.1"

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion contracts/dao/cwd-core/schema/cwd-core.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "cwd-core",
"contract_version": "0.2.0",
"contract_version": "0.2.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
2 changes: 1 addition & 1 deletion contracts/dao/cwd-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::state::{
PAUSED, PROPOSAL_MODULES, SUBDAO_LIST, TOTAL_PROPOSAL_MODULE_COUNT, VOTING_REGISTRY_MODULE,
};

pub(crate) const CONTRACT_NAME: &str = "crates.io:cwd-subdao-core";
pub(crate) const CONTRACT_NAME: &str = "crates.io:cwd-core";
pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

const PROPOSAL_MODULE_REPLY_ID: u64 = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cwd-pre-propose-overrule"
version = "0.2.0"
version = "0.2.1"
authors = ["oldremez"]
edition = "2021"
repository = "https://github.com/neutron-org/neutron-dao"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "cwd-pre-propose-overrule",
"contract_version": "0.2.0",
"contract_version": "0.2.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ fn is_subdao_legit(deps: &DepsMut, subdao_core: &Addr) -> Result<bool, PrePropos
);

match subdao {
Ok(subdao) => Ok(subdao.addr == *subdao_core),
Ok(subdao) => {
// sanity check to make sure that query returned correct subdao
let correct_subdao = subdao.addr == *subdao_core;
Ok(correct_subdao)
}
Err(_) => Ok(false),
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cwd-pre-propose-single"
version = "0.2.0"
version = "0.2.1"
authors = ["ekez <zekemedley@gmail.com>"]
edition = "2021"
repository = "https://github.com/DA0-DA0/dao-contracts"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "cwd-pre-propose-single",
"contract_version": "0.2.0",
"contract_version": "0.2.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use neutron_sdk::bindings::msg::NeutronMsg;

use cwd_pre_propose_base::{
error::PreProposeError,
msg::{ExecuteMsg as ExecuteBase, InstantiateMsg as InstantiateBase, QueryMsg as QueryBase},
msg::{
ExecuteMsg as ExecuteBase, InstantiateMsg as InstantiateBase, MigrateMsg,
QueryMsg as QueryBase,
},
state::PreProposeContract,
};
use schemars::JsonSchema;
Expand Down Expand Up @@ -119,3 +122,8 @@ pub fn execute(
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
PrePropose::default().query(deps, env, msg)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, PreProposeError> {
Ok(Response::default())
}
2 changes: 1 addition & 1 deletion contracts/dao/proposal/cwd-proposal-multiple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cwd-proposal-multiple"
version = "0.2.0"
version = "0.2.1"
authors = ["blue-note"]
edition = "2021"
repository = "https://github.com/DA0-DA0/dao-contracts"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "cwd-proposal-multiple",
"contract_version": "0.2.0",
"contract_version": "0.2.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down Expand Up @@ -2801,6 +2801,30 @@
},
"additionalProperties": false
},
{
"description": "Returns errors of the failed proposal. Expected in the form of \"codespace=? code=?\". Returns `Option<String>`",
"type": "object",
"required": [
"proposal_execution_error"
],
"properties": {
"proposal_execution_error": {
"type": "object",
"required": [
"proposal_id"
],
"properties": {
"proposal_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
Expand Down Expand Up @@ -7568,6 +7592,14 @@
}
}
},
"proposal_execution_error": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nullable_String",
"type": [
"string",
"null"
]
},
"proposal_hooks": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "HooksResponse",
Expand Down
24 changes: 24 additions & 0 deletions contracts/dao/proposal/cwd-proposal-multiple/schema/raw/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,30 @@
},
"additionalProperties": false
},
{
"description": "Returns errors of the failed proposal. Expected in the form of \"codespace=? code=?\". Returns `Option<String>`",
"type": "object",
"required": [
"proposal_execution_error"
],
"properties": {
"proposal_execution_error": {
"type": "object",
"required": [
"proposal_id"
],
"properties": {
"proposal_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nullable_String",
"type": [
"string",
"null"
]
}
24 changes: 21 additions & 3 deletions contracts/dao/proposal/cwd-proposal-multiple/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdResult,
Storage, SubMsg, WasmMsg,
to_binary, Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdError,
StdResult, Storage, SubMsg, WasmMsg,
};

use cw2::set_contract_version;
Expand All @@ -26,6 +26,7 @@ use cwd_voting::{
voting::{get_total_power, get_voting_power, validate_voting_period},
};

use crate::state::PROPOSAL_EXECUTION_ERRORS;
use crate::{msg::MigrateMsg, state::CREATION_POLICY};
use crate::{
msg::{ExecuteMsg, InstantiateMsg, QueryMsg},
Expand Down Expand Up @@ -730,6 +731,9 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::ProposalHooks {} => to_binary(&PROPOSAL_HOOKS.query_hooks(deps)?),
QueryMsg::VoteHooks {} => to_binary(&VOTE_HOOKS.query_hooks(deps)?),
QueryMsg::Dao {} => query_dao(deps),
QueryMsg::ProposalExecutionError { proposal_id } => {
query_proposal_execution_error(deps, proposal_id)
}
}
}

Expand Down Expand Up @@ -841,6 +845,11 @@ pub fn query_info(deps: Deps) -> StdResult<Binary> {
to_binary(&cwd_interface::voting::InfoResponse { info })
}

pub fn query_proposal_execution_error(deps: Deps, proposal_id: u64) -> StdResult<Binary> {
let error = PROPOSAL_EXECUTION_ERRORS.may_load(deps.storage, proposal_id)?;
to_binary(&error)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
let repl = TaggedReplyId::new(msg.id)?;
Expand All @@ -853,7 +862,16 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
}
None => Err(ContractError::NoSuchProposal { id: proposal_id }),
})?;
Ok(Response::new().add_attribute("proposal execution failed", proposal_id.to_string()))
// Error is reduced before cosmwasm reply and is expected in form of "codespace=? code=?"
let error = msg.result.into_result().err().ok_or_else(|| {
// should never happen since we reply only on failure
ContractError::Std(StdError::generic_err(
"must be an error in the failed result",
))
})?;
PROPOSAL_EXECUTION_ERRORS.save(deps.storage, proposal_id, &error)?;

Ok(Response::new().add_attribute("proposal_execution_failed", proposal_id.to_string()))
}
TaggedReplyId::FailedProposalHook(idx) => {
let addr = PROPOSAL_HOOKS.remove_hook_by_index(deps.storage, idx)?;
Expand Down
5 changes: 5 additions & 0 deletions contracts/dao/proposal/cwd-proposal-multiple/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ pub enum QueryMsg {
/// module.
#[returns(HooksResponse)]
VoteHooks {},
/// Returns errors of the failed proposal.
/// Expected in the form of "codespace=? code=?".
/// Returns `Option<String>`
#[returns(Option<String>)]
ProposalExecutionError { proposal_id: u64 },
}

#[cw_serde]
Expand Down
2 changes: 2 additions & 0 deletions contracts/dao/proposal/cwd-proposal-multiple/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ pub const VOTE_HOOKS: Hooks = Hooks::new("vote_hooks");
/// The address of the pre-propose module associated with this
/// proposal module (if any).
pub const CREATION_POLICY: Item<ProposalCreationPolicy> = Item::new("creation_policy");
/// Execution errors for proposals that do not close on failure (Config.close_proposal_on_execution_failure set to false)
pub const PROPOSAL_EXECUTION_ERRORS: Map<u64, String> = Map::new("proposal_execution_errors");
Loading