-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from CoinFabrik/44-update-vulnerability-and-de…
…tector-documentation-for-milestone-1 44 update vulnerability and detector documentation for milestone 1 Closes #44
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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
56 changes: 56 additions & 0 deletions
56
detectors/unprotected-update-current-contract-wasm/README.md
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,56 @@ | ||
# Unprotected update of current contract wasm | ||
|
||
### What it does | ||
|
||
It warns you if `update_current_contract_wasm()` function is called without a previous check of the address of the caller. | ||
|
||
### Why is this bad? | ||
|
||
If users are allowed to call `update_current_contract_wasm()`, they can intentionally modify the contract behaviour, leading to the loss of all associated data/tokens and functionalities given by this contract or by others that depend on it. | ||
|
||
### Example | ||
|
||
```rust | ||
#[contractimpl] | ||
impl UpgradeableContract { | ||
pub fn init(e: Env, admin: Address) { | ||
e.storage().instance().set(&DataKey::Admin, &admin); | ||
} | ||
|
||
pub fn version() -> u32 { | ||
1 | ||
} | ||
|
||
pub fn upgrade(e: Env, new_wasm_hash: BytesN<32>) { | ||
let admin: Address = e.storage().instance().get(&DataKey::Admin).unwrap(); | ||
|
||
e.deployer().update_current_contract_wasm(new_wasm_hash); | ||
} | ||
} | ||
``` | ||
|
||
Use instead: | ||
|
||
```rust | ||
#[contractimpl] | ||
impl UpgradeableContract { | ||
pub fn init(e: Env, admin: Address) { | ||
e.storage().instance().set(&DataKey::Admin, &admin); | ||
} | ||
|
||
pub fn version() -> u32 { | ||
1 | ||
} | ||
|
||
pub fn upgrade(e: Env, new_wasm_hash: BytesN<32>) { | ||
let admin: Address = e.storage().instance().get(&DataKey::Admin).unwrap(); | ||
admin.require_auth(); | ||
|
||
e.deployer().update_current_contract_wasm(new_wasm_hash); | ||
} | ||
} | ||
``` | ||
|
||
### Implementation | ||
|
||
The detector's implementation can be found at [this link](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/unprotected-update-current-contract-wasm) |
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