Skip to content

Commit

Permalink
test: CEI pattern violation in intrinsic arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov committed Nov 13, 2022
1 parent 1562239 commit e9e7578
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
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']
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" }
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
}
);
}
}
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

0 comments on commit e9e7578

Please sign in to comment.