-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.sw
42 lines (35 loc) · 1.05 KB
/
main.sw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
contract;
abi TestUnprotectedInitialization {
#[storage(write)]
fn unsafe_init(value: u64);
#[storage(read, write)]
fn safe_init1(value: u64);
#[storage(read, write)]
fn safe_init2(value: u64);
}
storage {
initialized: bool = false,
value: u64 = 0,
}
impl TestUnprotectedInitialization for Contract {
// Report entry should be created:
// L23: The `Contract::unsafe_init` function is an unprotected initializer function. Consider adding a requirement to prevent it from being called multiple times.
#[storage(write)]
fn unsafe_init(value: u64) {
storage.value.write(value);
}
// Report entry should not be created
#[storage(read, write)]
fn safe_init1(value: u64) {
require(!storage.initialized.read(), "Already initialized");
storage.value.write(value);
}
// Report entry should not be created
#[storage(read, write)]
fn safe_init2(value: u64) {
if storage.initialized.read() {
revert(0);
}
storage.value.write(value);
}
}