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

Audit Fixes and Improvements #742

Merged
merged 59 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4b1398c
Add missing hooks to dao-voting-native-staked, start adding tests
JakeHartnell Sep 1, 2023
de50a62
Fix group contract attribute key emits "address"
JakeHartnell Sep 1, 2023
fbad6e7
Fix absoluteCount can be configured to be greater than the total
Sep 2, 2023
2a50a0b
Fix absoluteCount threshold for a new token is not validated
Sep 2, 2023
cdb8da2
Fix issuer contract can be blacklisted
Sep 2, 2023
74420d1
Fix Stargaze collection info bug, and absolute count validation
Sep 2, 2023
583db0c
Fix incorrect events are emitted for whitelist
Sep 2, 2023
c82fdd3
Fix lack of denom validation
Sep 2, 2023
d3ad487
Fix BEFORE_SEND_HOOK_FEATURES_ENABLED is not exposed through smart qu…
Sep 2, 2023
c6cf16d
Fix misleading from attribute when burning funds
Sep 2, 2023
c02a52a
Fix broken tests from denom validation
Sep 2, 2023
56159d2
Fix inconsistent attribute namings and orderings
Sep 2, 2023
27c1602
Fix INITITIAL_NFTS spelling XD
Sep 2, 2023
89cf32b
Fix counterintuitive variable namings
Sep 2, 2023
8bcae64
Better API for cw-tokenfactory-issuer
Sep 2, 2023
3b75780
Appease clippy gods
Sep 2, 2023
ce4e4fc
Reduce unneeded gas consumption by setting admin directly
JakeHartnell Sep 2, 2023
df1591b
Fix unneeded reply_always when instantiating new token
JakeHartnell Sep 2, 2023
bfff543
Remove unused function
JakeHartnell Sep 2, 2023
360297a
Improve comments
JakeHartnell Sep 2, 2023
527a600
Use “Migrate only if newer” pattern
JakeHartnell Sep 2, 2023
b4256b1
Clean up and fix issuer test-tube tests
JakeHartnell Sep 2, 2023
2781cec
Combine all dao-related hooks into a single package
JakeHartnell Sep 2, 2023
f96e6e4
Improve code resuse by consilidating stake hooks
JakeHartnell Sep 2, 2023
17928bc
Clean up types
JakeHartnell Sep 3, 2023
51c79c0
Remove need for unused TokenFactoryQuery, use shared stake hooks
JakeHartnell Sep 3, 2023
f20b1cb
Fix stake hook tests, update schema
JakeHartnell Sep 3, 2023
dc48b30
Incorporate NFT staking hooks into dao-hooks package
JakeHartnell Sep 3, 2023
2b04dbc
Add cw4::MemberChangedHookMsg and clean up dao-hooks pkg
JakeHartnell Sep 3, 2023
e48211f
Make clippy happy, use only migrate newer across all voting contracts
JakeHartnell Sep 3, 2023
426d139
cargo fmt
JakeHartnell Sep 3, 2023
c2c230d
clippy on latest rust version
JakeHartnell Sep 3, 2023
318cea5
Improve unstaking_duration validation reuse
Sep 5, 2023
8c1b31f
Allowlist should apply to transfers from *or to* an address
JakeHartnell Sep 5, 2023
8883b75
Add info on renouncing Token Factory Admin
JakeHartnell Sep 5, 2023
a8683f4
Remove outdated comments
JakeHartnell Sep 5, 2023
2cb2d59
Remove commented out metadata test
JakeHartnell Sep 5, 2023
f2d4ac3
More informative error to address BlockBeforeSend hook executing on m…
JakeHartnell Sep 5, 2023
5953169
Use tagged versions or upstream git repos for deps
JakeHartnell Sep 5, 2023
dd93317
Better code documentation for cw-tokenfactory-issuer
JakeHartnell Sep 5, 2023
7633b3e
Make it possible to unset BeforeSendHook, or set to a different contract
JakeHartnell Sep 5, 2023
0115fe7
Default to BeforeSendHook features being disabled
JakeHartnell Sep 5, 2023
dc7af3c
BeforeSendHook refactor and tests
JakeHartnell Sep 6, 2023
508d81c
Cleanup TODO, verify correct error
JakeHartnell Sep 6, 2023
8c54bf2
Accurate comment
JakeHartnell Sep 9, 2023
fa1a74a
Improve active threshold validation reuse
JakeHartnell Sep 9, 2023
71137e8
Don't create issuer for existing tokens
JakeHartnell Sep 9, 2023
b6f9c04
Reorg so we can have only one native token voting contract
JakeHartnell Sep 9, 2023
c46597e
No need to have an issuer for existing tokens
JakeHartnell Sep 9, 2023
cc764d0
Update Schema
JakeHartnell Sep 9, 2023
87aaf6d
Fix up integration tests
JakeHartnell Sep 11, 2023
21e91ee
Remove owner from dao-voting-cw721-staked
JakeHartnell Sep 11, 2023
2d40452
Improve TF docs
JakeHartnell Sep 11, 2023
4778813
Implement two-step ownership transfer for cw_tokenfactory_issue
JakeHartnell Sep 12, 2023
c232173
Tests for renouncing ownership
JakeHartnell Sep 12, 2023
be1ae92
Fix package name.
JakeHartnell Sep 12, 2023
1c51285
Fix integration tests
JakeHartnell Sep 12, 2023
26e24dd
set_before_update_hook -> set_before_send_hook
JakeHartnell Sep 12, 2023
67e8b83
Address remaining TODOs
JakeHartnell Sep 12, 2023
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: 13 additions & 6 deletions contracts/voting/dao-voting-native-staked/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ pub fn instantiate(
CONFIG.save(deps.storage, &config)?;
DAO.save(deps.storage, &info.sender)?;

// 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

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

Copy link
Member Author

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.

if let Some(active_threshold) = msg.active_threshold.as_ref() {
match active_threshold {
ActiveThreshold::AbsoluteCount { count } => {
assert_valid_absolute_count_threshold(deps.as_ref(), &msg.denom, *count)?;
assert_valid_absolute_count_threshold(*count, supply.amount)?;
}
ActiveThreshold::Percentage { percent } => {
if *percent > Decimal::percent(100) || *percent <= Decimal::percent(0) {
Expand All @@ -85,15 +93,13 @@ pub fn instantiate(
}

pub fn assert_valid_absolute_count_threshold(
deps: Deps,
token_denom: &str,
count: Uint128,
supply: Uint128,
) -> Result<(), ContractError> {
if count.is_zero() {
return Err(ContractError::ZeroActiveCount {});
}
let supply: Coin = deps.querier.query_supply(token_denom.to_string())?;
if count > supply.amount {
if count > supply {
return Err(ContractError::InvalidAbsoluteCount {});
}
Ok(())
Expand Down Expand Up @@ -285,7 +291,8 @@ pub fn execute_update_active_threshold(
}
ActiveThreshold::AbsoluteCount { count } => {
let denom = CONFIG.load(deps.storage)?.denom;
assert_valid_absolute_count_threshold(deps.as_ref(), &denom, count)?;
let supply: Coin = deps.querier.query_supply(denom.to_string())?;
assert_valid_absolute_count_threshold(count, supply.amount)?;
}
}
ACTIVE_THRESHOLD.save(deps.storage, &active_threshold)?;
Expand Down
3 changes: 3 additions & 0 deletions contracts/voting/dao-voting-native-staked/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub enum ContractError {
#[error("Unauthorized")]
Unauthorized {},

#[error("Denom does not exist on chain")]
InvalidDenom {},

#[error("Invalid unstaking duration, unstaking duration cannot be 0")]
InvalidUnstakingDuration {},

Expand Down
19 changes: 19 additions & 0 deletions contracts/voting/dao-voting-native-staked/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ fn test_instantiate_invalid_unstaking_duration_height() {
);
}

#[test]
#[should_panic(expected = "Denom does not exist on chain")]
fn test_instantiate_invalid_denom() {
let mut app = mock_app();
let staking_id = app.store_code(staking_contract());

// Populated fields with height
instantiate_staking(
&mut app,
staking_id,
InstantiateMsg {
// This denom has zero supply
denom: "uinvalid2".to_string(),
unstaking_duration: None,
active_threshold: None,
},
);
}

#[test]
#[should_panic(expected = "Invalid unstaking duration, unstaking duration cannot be 0")]
fn test_instantiate_invalid_unstaking_duration_time() {
Expand Down