-
Notifications
You must be signed in to change notification settings - Fork 142
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
Audit Fixes and Improvements #742
Conversation
sg721 has two addresses that control it. The `minter` which can mint NFTs, and the `creator` which can update collection metadata and royalties. We now set both of those to be the DAO.
Many of these methods are not needed thanks to Authz.
DAOs may wish to disable the BeforeSendHook at some point, or potentially set it to a custom cosmwasm contract if they wish to customize functionality a bit more. Modifies the SetBeforeSendHook method to allow for this, and adds tests that it's indeed possible to set it to nil.
These are powerful features, but many may not want them as they can be abused. DAOs that want these features will have to explicitly enable them via a governance prop.
Welcome to Codecov 🎉Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment. Thanks for integrating Codecov - We've got you covered ☂️ |
The concept of ownership doesn't really make sense for voting contracts. IMO the owner should always be the DAO.
contracts/external/cw-tokenfactory-issuer/tests/cases/set_before_update_hook.rs
Outdated
Show resolved
Hide resolved
// Validate denom by checking supply | ||
let supply: Coin = deps.querier.query_supply(msg.denom.to_string())?; | ||
println!("supply {:?}", supply); | ||
if Uint128::is_zero(&supply.amount) { | ||
return Err(ContractError::InvalidDenom {}); | ||
} | ||
|
||
// Validate active threshold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good to me! There is just a println remaining in line 71 that looks like its left over from debugging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silly me! Thanks for catching that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn beast.
pub fn execute_stake_hook( | ||
deps: DepsMut, | ||
_env: Env, | ||
_info: MessageInfo, | ||
stake_hook: StakeChangedHookMsg, | ||
) -> Result<Response, ContractError> { | ||
match stake_hook { | ||
StakeChangedHookMsg::Stake { .. } => { | ||
let mut count = STAKE_COUNTER.load(deps.storage)?; | ||
count += Uint128::new(1); | ||
STAKE_COUNTER.save(deps.storage, &count)?; | ||
} | ||
StakeChangedHookMsg::Unstake { .. } => { | ||
let mut count = STAKE_COUNTER.load(deps.storage)?; | ||
count += Uint128::new(1); | ||
STAKE_COUNTER.save(deps.storage, &count)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both Stake
and Unstake
adding to the counter look like a mistake unless you are tracking something like "total number of operations". Can you please check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Total number of operations.
VALIDATE_ABSOLUTE_COUNT_FOR_NEW_NFT_CONTRACTS => { | ||
// Check that absolute count is not greater than supply | ||
// NOTE: we have to check this in a reply as it is potentially possible | ||
// to include non-mint messages in `initial_nfts`. | ||
if let Some(ActiveThreshold::AbsoluteCount { count }) = | ||
ACTIVE_THRESHOLD.may_load(deps.storage)? | ||
{ | ||
// Load config for nft contract address | ||
let collection_addr = CONFIG.load(deps.storage)?.nft_address; | ||
|
||
// Query the total supply of the NFT contract | ||
let supply: NumTokensResponse = deps | ||
.querier | ||
.query_wasm_smart(collection_addr, &Cw721QueryMsg::NumTokens {})?; | ||
|
||
// Chec the count is not greater than supply | ||
if count > Uint128::new(supply.count.into()) { | ||
return Err(ContractError::InvalidActiveCount {}); | ||
} | ||
} | ||
Ok(Response::new()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only partially remediates issue 7; there can still be a supply of zero NFTs if an ActiveThreshold::Percentage
is in place.
Address most of the issues from the recent smart contract audit, also fixes one or two things they didn't catch. Many improvements across the board.
Additionally:
Major changes from the current
development
version:dao-voting-native-staked
anddao-voting-token-factory-staked
have been merged into one contract to reduce code duplication. When using anexisting
token, a newcw_tokenfactory_issuer
is no longer instantiated as it was pointless and it would be impossible to garuntee if the admin would be set correctly.cw_tokenfactory_issuer
has been greatly simplified.cw_tokenfactory_issuer
usescw_ownable
to implement two-step ownership transfer, as well as to allow for DAOs to easily reject ownership altogether.dao-voting-cw721-staked
is now consistent with the other voting modules in terms of not taking anowner
, the owner of a voting module should always be the DAO.freezing
,denylist
, and more are disabled by default incw_tokenfactory_issuer
. DAOs must explicitly vote to enable them later so everyone can see what they are getting into.dao-hooks
package to allow for better code reuse. A newDaoHooks
enum contains all hooks used in the codebase to make it easy to write generic contracts leveraging any DAO hook.BeforeSendHook
, renouncing ownership, and disabling Token Factory admin have been documented and tested.In addition, many other improvements have been added, including numerous small informational issues (non-critical) mentioned in the audit.