casper-network / casper-network/casper-node

Upgradable immutable smart contracts.

Open
#4,510 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
399
Forks
224
Avg merge
15h 44m
Merged PRs (30d)
2

Description

Casper has upgradable contracts, but only contracts owned by an account can be upgraded. It is mostly undesirable setup, especially if you want to trust the contract. In case of an account-owned contracts, the account can be compromised and new version of contract with malicious code can be deployed. It forces smart contract developers to deploy immutable contracts or use some kind of proxy pattern.

I propose to allow smart contract to upgrade itself. Here is how a simple upgradable DAO could work.

1. The DAO smart contract is deployed. It holds a list of members and each member has a single vote.
2. A security researcher finds a bug in the DAO smart contract and reports it to the DAO (over Discord).
3. DAO members agree to upgrade the contract with the fix. Here is what needs to happen.
4. In the first step they allow the security researcher to propose a new version of a contract. Through the voting process they have to make the contract to call the host:
```rust
casper_host::allow_contract_upgrader(Address("0xSecurityResearcher"));
```
5. Now that the security researcher is allowed to propose a new version, they build a new code into a WASM file. Then deploy it to the network. The `call` methods, instead of installing this contract, needs to propose it as a new version of another contract.
```rust
let upgrade_id = casper_host::propose_contract_upgrade(
Address("0xDAO"),
contract_entrypoints,
);
```
6. Now the DAO needs to vote one more time to accept the new version. If the vote is successful, then the DAO contract should call the host:
```rust
casper_host::upgrade(upgrade_id);
```

Above solution:
- prevents DOSing contract with new versions, by whitelisting possible upgraders,
- allows contracts to have their own logic of deciding when to make upgrades,
- is quite simple.

More details can be explored, but first I'd like discuss the idea of upgrading immutable contracts in general.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.