-
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
Cwd proposal delegate #562
Draft
baoskee
wants to merge
25
commits into
main
Choose a base branch
from
cwd-proposal-delegate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6d8035d
init cwd-proposal-delegate
baoskee 5a7afcf
Msg + Error + State design
baoskee 3ccfe6d
Skeleton code setup
baoskee c0383c2
execute and state redesign for security
baoskee afab973
execute_delegate and execute_remove_delegation
baoskee 9642d52
execute_execute body
baoskee d54df15
Reply implementation for submessage
baoskee 0a995fc
Query functions
baoskee 1fd25d2
Added smart contract risks section
baoskee a474388
Update contracts/proposal/cwd-proposal-delegate/Cargo.toml
baoskee 4d679b0
Update contracts/proposal/cwd-proposal-delegate/Cargo.toml
baoskee b8c9830
Merge https://github.com/DA0-DA0/dao-contracts into cwd-proposal-dele…
baoskee a103eee
new cargo.toml
baoskee cf21c54
Removed exposure of delegation count
baoskee 683ccd8
merged
baoskee 2a3ea2a
test shell
baoskee f433008
Added testing strategy
baoskee d44ffb7
test unauthorized delegation
baoskee d3513e9
execute_authorization tests
baoskee b003b9a
Expiration test
baoskee 07f2358
Revocable policy and delegation not found error path
baoskee b0e54d0
First try at testing submessage
baoskee 5c1bc28
Added pagination query for delegations
baoskee c635cca
Reply hook testing
baoskee b8e34e3
refactor to policy_module_irrevocable
baoskee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[alias] | ||
wasm = "build --release --lib --target wasm32-unknown-unknown" | ||
unit-test = "test --lib" | ||
schema = "run --bin schema" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Build results | ||
/target | ||
/schema | ||
|
||
# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327) | ||
.cargo-ok | ||
|
||
# Text file backups | ||
**/*.rs.bk | ||
|
||
# macOS | ||
.DS_Store | ||
|
||
# IDEs | ||
*.iml | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
[package] | ||
name = "cwd-proposal-delegate" | ||
version = "1.0.0-beta" | ||
authors = ["baoskee"] | ||
edition = "2021" | ||
repository = "https://github.com/DA0-DA0/dao-contracts" | ||
description = "Proposal execute delegation to any smart contract" | ||
exclude = [ | ||
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. | ||
"contract.wasm", | ||
"hash.txt", | ||
] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
# for more explicit tests, cargo test --features=backtraces | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
# use library feature to disable all instantiate/execute/query exports | ||
library = [] | ||
|
||
[dependencies] | ||
cosmwasm-std = { workspace = true, features = ["ibc3"] } | ||
cosmwasm-storage = { workspace = true } | ||
cosmwasm-schema = { workspace = true } | ||
cw-storage-plus = { workspace = true } | ||
cw-utils = { workspace = true } | ||
cw2 = { workspace = true } | ||
cw20 = { workspace = true } | ||
cw3 = { workspace = true } | ||
thiserror = { version = "1.0" } | ||
dao-core = { workspace = true, features = ["library"] } | ||
dao-macros = { workspace = true } | ||
dao-pre-propose-base = { workspace = true } | ||
dao-interface = { workspace = true } | ||
dao-voting = { workspace = true } | ||
cw-hooks = { workspace = true } | ||
cw-paginate = { workspace = true } | ||
dao-proposal-hooks = { workspace = true } | ||
dao-vote-hooks = { workspace = true } | ||
dao-pre-propose-multiple = { workspace = true } | ||
voting-v1 = { workspace = true } | ||
|
||
[dev-dependencies] | ||
cw-multi-test = { workspace = true } | ||
dao-voting-cw4 = { workspace = true } | ||
dao-voting-cw20-balance = { workspace = true } | ||
dao-voting-cw20-staked = { workspace = true } | ||
dao-voting-native-staked = { workspace = true } | ||
dao-voting-cw721-staked = { workspace = true } | ||
cw-denom = { workspace = true } | ||
dao-testing = { workspace = true } | ||
cw20-stake = { workspace = true } | ||
cw20-base = { workspace = true } | ||
cw721-base = { workspace = true } | ||
cw4 = { workspace = true } | ||
cw4-group = { workspace = true } | ||
rand = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Introduction | ||
|
||
Delegation is basically: “we trust you have the judgment, we give you the power to do this specific action within some X time frame. You have the right but not the obligation.” | ||
|
||
## Examples | ||
- You have the power to kick this specific member after review. Perhaps you make an investigative committee after a member is accused of something, and delegate the power to a multisig to execute the message: “Kick this member” | ||
- You can pause one of our SubDAOs for 1 week if necessary | ||
- You have the power to add a specific item to our DAO config at any time | ||
- You have the power to increase Bob’s salary by 800 JUNO through DAO treasury | ||
- Liquidate 8000 JUNO through JunoSwap at any time. Perhaps you want to delegate this to a hedge fund who promises to “time the market” | ||
|
||
## When would it not be useful? | ||
|
||
- **You can compose it through something other than a proposal module**. A separate option contract. However, this would not allow you to execute messages through the core module. Only proposal modules can pass messages through the core module. | ||
- In order to control Treasury funds, you can siphon off to a SubDAO, and then SubDAO can make the decisions. However, this does not constrain the action of the SubDAO. It can totally misuse those funds. We want allowance of specific and concrete messages. | ||
- In most cases, an escrow contract would do the job, but in certain cases, we want to be very granular with the actions we delegate | ||
|
||
## When would it be useful? | ||
|
||
- **For specific, constrained DAO-related actions**. For the things the DAO control and in which an escrow would give too much power over the resource. The DAO wants delegation on specific message that gives the delegate constrained power | ||
- **Time-based actions**. Actions where the time of execution matters, and an executive decision maker needs power to execute at any time | ||
- **Judgment-based actions**. Perhaps another DAO or oracle service specializes in identity-proving activities, and you would like to mark certain members as a real person for some sort of one person one vote thing. Or, perhaps, you want to remove a multisig member, and decide to delegate said action to a Judiciary DAO, some sort of tribunal | ||
|
||
|
||
|
||
# Design | ||
|
||
This is kind of a “messages escrow” module in which the execution of the proposal is wrapped into an option and execution is given to another party. | ||
|
||
|
||
It would be a “proposal module” that allows arbitrary wrapping of messages, and would be required for the DAO to add as a Proposal Module. However, it would not use a voting module, but rather, another proposal module like `cwd-proposal-single` would pass a delegation message to the Core module, whereby the core module would execute a delegation message. | ||
|
||
Execution messages: | ||
|
||
```rust | ||
// Gives back a delegation ID | ||
Delegate { msgs: Vec<CosmosMsg<Empty>>, addr: String, expiration: Expiration } | ||
// Authorized execution only | ||
Execute { delegation_id: u64 } | ||
``` | ||
|
||
State: | ||
|
||
```rust | ||
struct Config { | ||
admin: Addr, | ||
} | ||
|
||
struct Delegation { | ||
addr: Addr, | ||
msgs: Vec<CosmosMsg<Empty>>, | ||
expiration: Expiration, | ||
} | ||
|
||
const DELEGATIONS: Map<u64, Delegation> = Map::new("delegations"); | ||
const CONFIG: Item<Config> = Item::new("config"); | ||
``` | ||
|
||
## How could a DaoDao core module use this? | ||
|
||
1. Add as a proposal module | ||
2. Pass a delegation message through another proposal module (single or multiple-choice) as a Wasm message (converted into Cosmos message) | ||
|
||
```rust | ||
WasmMsg::Execute { | ||
contract_addr: // address of Delegation Proposal Module | ||
msg: to_binary(&DelegationExecuteMsg::Delegate { | ||
msgs: // Cosmos messages to delegate, | ||
addr: "0x2342", // Delegate with power to execute, possibly another DAO | ||
expiration: 123123324 | ||
})?, | ||
funds: vec![] | ||
} | ||
``` | ||
|
||
3. The delegate has the power to execute said proposal through the Delegate Proposal Module at any time up until expiration. Said execution would go through the DaoDao core module | ||
|
||
|
||
# Smart Contract Risks | ||
Proposal modules can route arbitrary messages to | ||
the core module so we have to take special care. | ||
I can classify risks into these domains: | ||
* Un-authorized delegation | ||
* Un-authorized execution | ||
* Un-authorized revocation | ||
* Multiple execution | ||
* Expired execution | ||
|
||
Policy risks: | ||
* Forbidden revoking when policy enabled | ||
* Does not preserve on failure when policy enabled | ||
|
||
|
||
Of all the risks, un-authorized delegation will definitely | ||
compromise the core module. |
11 changes: 11 additions & 0 deletions
11
contracts/proposal/cwd-proposal-delegate/src/bin/schema.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use cosmwasm_schema::write_api; | ||
|
||
use cwd_proposal_delegate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; | ||
|
||
fn main() { | ||
write_api! { | ||
instantiate: InstantiateMsg, | ||
execute: ExecuteMsg, | ||
query: QueryMsg, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
all of these can be
cosmwasm-x = { workspace = true }