-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: CEI pattern violation in intrinsic arguments
- Loading branch information
1 parent
1562239
commit e9e7578
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...st_programs/should_pass/static_analysis/cei_pattern_violation_in_intrinsic_call/Forc.lock
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,13 @@ | ||
[[package]] | ||
name = 'cei_pattern_violation_in_intrinsic_call' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-8075CAB8EEC6376F' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-8075CAB8EEC6376F' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
...st_programs/should_pass/static_analysis/cei_pattern_violation_in_intrinsic_call/Forc.toml
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,8 @@ | ||
[project] | ||
name = "cei_pattern_violation_in_intrinsic_call" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
29 changes: 29 additions & 0 deletions
29
..._programs/should_pass/static_analysis/cei_pattern_violation_in_intrinsic_call/src/main.sw
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,29 @@ | ||
contract; | ||
|
||
use std::storage::store; | ||
|
||
abi TestAbi { | ||
#[storage(write)] | ||
fn deposit(amount: u64); | ||
} | ||
|
||
impl TestAbi for Contract { | ||
#[storage(write)] | ||
fn deposit(amount: u64) { | ||
// 1st intrinsic argument is a code block with interaction | ||
// 2nd intrinsic argument is a code block with effect | ||
__add( | ||
{ | ||
// interaction | ||
abi(TestAbi, 0x3dba0a4455b598b7655a7fb430883d96c9527ef275b49739e7b0ad12f8280eae).deposit(amount); | ||
21 | ||
}, | ||
{ | ||
// effect -- therefore violation of CEI where effect should go before interaction | ||
// (assuming left-to-right function argument evaluation) | ||
store(0x3dba0a4455b598b7655a7fb430883d96c9527ef275b49739e7b0ad12f8280eae, ()); | ||
21 | ||
} | ||
); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...st_programs/should_pass/static_analysis/cei_pattern_violation_in_intrinsic_call/test.toml
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,3 @@ | ||
category = "compile" | ||
|
||
# check: $()Storage modification after external contract interaction in function or method "deposit". Consider making all storage writes before calling another contract |