-
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 #164 from CoinFabrik/163-add-documentation-for-zer…
…o-or-test-address 163 add documentation for zero or test address
- Loading branch information
Showing
3 changed files
with
52 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
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,43 @@ | ||
# Zero or test address | ||
|
||
### What it does | ||
Checks whether the zero address is being inputed to a function without validation. | ||
|
||
### Why is this bad? | ||
Because the private key for the zero address is known, anyone could take ownership of the contract. | ||
|
||
### Example | ||
|
||
```rust | ||
pub fn set(e: Env, admin: Address, data: i32) -> Result<(), Error> { | ||
if !ZeroAddressContract::ensure_is_admin(&e, admin)? { | ||
return Err(Error::NotAdmin); | ||
} | ||
e.storage().persistent().set(&DataKey::Data, &data); | ||
Ok(()) | ||
} | ||
``` | ||
|
||
|
||
Use instead: | ||
```rust | ||
pub fn set(e: Env, admin: Address, data: i32) -> Result<(), Error> { | ||
if admin | ||
== Address::from_string(&String::from_bytes( | ||
&e, | ||
b"GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF", | ||
)) | ||
{ | ||
return Err(Error::InvalidNewAdmin); | ||
} | ||
if !ZeroAddressContract::ensure_is_admin(&e, admin)? { | ||
return Err(Error::NotAdmin); | ||
} | ||
e.storage().persistent().set(&DataKey::Data, &data); | ||
Ok(()) | ||
} | ||
``` | ||
|
||
### Implementation | ||
|
||
The detector's implementation can be found at [this link](https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/zero-or-test-address). |
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