Giter VIP home page Giter VIP logo

contracts's People

Contributors

adairrr avatar bhiiktor avatar cyberhoward avatar cyonis avatar dependabot[bot] avatar jonhoo avatar kayanski avatar koeding avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

adairrr

contracts's Issues

Move away from canonical address transformations and use the Addr instead

Background


This was a finding from the WW security audit.

Canonical address transformations are inefficient

While previously recommended as a best practice, usage of canonical addresses is no longer encouraged. The background is that canonical addresses are no longer stored in a canonical format, so the transformation just adds overhead without much benefit. Additionally, the codebase is more complicated with address transformations.

Recommendation

We recommend removing any transformation from human to canonical addresses and using the new Addr type for validated addresses instead.


Definition of Done

The objective of this task is to move away from the canonical transformations and instead use the Addr type.

[Analysis] Generalized dApp instantiate message

When creating a dApp we would like to give the root user the flexibility to set certain parameters yet restrict some others to default values.

This could be done by splitting all dapp InstantiateMsgs to be of the structure:
pub struct GeneralInstantiateMsg { pub base: BaseInstantiateMsg, // Set by manager with default values pub user_input_msg: Binary, // Message provided by root on dApp init }

This way certain variables (like the treasury address and memory address) can't be altered on init.
This would however limit the flexibility as there would be no easy way to add other dapp specific constants to the base init msg.

Another approach could be to implement a factory contract that holds a map of structs with a common trait. The trait would implement a method to fill out a user-input field and keep the rest as default, and create the dapp as such. This would not only be usefull for dApps but for services/contracts we'd like to provide.

Would love some discussion on this!

[DApp-base] Change trader to traders

The dapp_base currently only allows to set one trader. In some cases it could be usefull to have multiple traders allowed.

  • Change trader in state.rs to traders: Vec<Addr>
  • Add function to add/remove traders

[DApp-Base] Import dapp_base instead of copying it into each module

Background


This was a finding from the security audit of WW.

The file contracts/treasury/dapps/terraswap/src/dapp_base/common.rs is copied into every dapp contract. This is inefficient, replicates the code and is prone to human error if hard-coded addresses change and have to be modified everywhere.

Recommendation

We recommend putting the file into a package and importing it.


Definition of Done

  • dapp_base made into a package
  • Imported

[Analysis] OS Security, upgradability of contracts

While it is advantageous to have upgradable contracts it also adds security risks.

As security is a nr. 1 priority it's important to have a basic guideline around what contract should be upgradable, who should be the person able to upgrade them and how is the upgrade process handled.

In this analysis we can recognize two groups of contracts:

  1. Pandora contracts
  • The contracts that are direct dependencies for the OS should not be upgradable. Upgrading these contracts should be done by creating a new contract and making it optional to update to the new contract by a config setter.
  • All internal contracts should be upgradable through gov process
  1. OS contracts
  • Almost all contracts should be upgradable with the permissions to change the underlying code_id given to the Manager contract.
  • Critical Pandora contract dependencies can be changed by the root user through config setters

[DApp-base] Remove ability to update treasury/memory address

The base_dapp packages/dao_os/src/treasury/dapp_base currently allows the Admin of the contract to change the Treasury and Memory addresses. This should never have to be done so it should be removed.

The relevant tests should also be updated.

[Analysis] Overcoming gas limits

A general issue exist when trying to scale on-chain solutions. The problem is the fact that transaction are gas constrained. This means that some atomic transactions, like changing a parameter on a large set of objects, might not be possible in one transaction.

The proposed solution here is to split the operation in different parts. An example of this problem is the asset value calculation inside the Treasury contract. Should the amount of assets and references grow to large, the query becomes impossible to perform.

To mitigate this issue one can implement the following:

  1. Lock the set of objects you'd like to perform the action on
  2. Perform the action through pagination and keep a record of the last element and an accumulator if needed.
  3. When you traversed the whole set you unlock the object.

I've tried to implement a general solution to this as i needed it.

fn page<T,R>(deps: Deps, limit: Option<u32>, f: fn(T, &mut R), mut accumulator: R, start_after: Option<&str>, object: Map<&str,T>) -> (Option<String>, R)
where
T: Serialize + DeserializeOwned,
{
    let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize;
    let start = start_after.map(Bound::exclusive);
    let result: Vec<Vec<u8>> = object
        .range(deps.storage, start, None, Order::Ascending)
        .take(limit)
        .map(|item| { let (key, element) = item.unwrap(); f(element, &mut accumulator); key})
        .collect();

    let last: Option<String> = result.last().clone().map(|key| String::from(std::str::from_utf8(key).unwrap()));
    (last.clone(), accumulator)
}

Limit is the amount of items iterated over in each function call. This should be provided in the call as it depends on how much computation is required for each function call.

The returned key and accumulator can be stored in the contract to be used in the next call.
I think it might be interesting to create a wrapper around MAP something like PagedMap where we implement these functions.

[Analysis] Complexity and effort of adding a time lock contract

We have many ways that Admins can induce changes in our contracts. The objective of this story is to analyze where we can implement time lock functionality. This could both be used for the entirety of Pandora and as a "plugin" that customers could choose to implement in their own contracts.

A description of time lock contracts in general (for use in yield farming at least) can be found here.

In solidity-based contracts, the most widely-used timelock contract was written by Compound and can be found here.

Update Treasury VaultAsset addition/updates

The addresses held in the treasury should be stored as a function of the Memory contract storage.

When adding a new vaultasset we should only need to specify the names of the assets . The contract should query the Memory contract for their actual addresses.

This way full control over updates are still handled by the OS admins while instantiation, etc. Remains very easy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.