Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

seal_reentrant_count returns contract reentrant count #12695

Merged
merged 32 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a8214fd
Add logic, test, broken benchmark
yarikbratashchuk May 18, 2022
143c158
Merge branch 'master' into seal_reentrant_count
yarikbratashchuk May 20, 2022
219eb84
Merge branch 'master' into seal_reentrant_count
yarikbratashchuk May 22, 2022
fccd751
account_entrance_count
yarikbratashchuk May 23, 2022
0a70239
Addressing comments
yarikbratashchuk May 29, 2022
6f3655a
Address @agryaznov's comments
yarikbratashchuk Jun 1, 2022
f29884b
Add test for account_entrance_count, fix ci
yarikbratashchuk Jun 2, 2022
72c8f83
Cargo fmt
yarikbratashchuk Jun 2, 2022
0f6f894
Fix tests
yarikbratashchuk Jun 2, 2022
949c438
Fix tests
yarikbratashchuk Jun 5, 2022
f34b6da
Remove delegated call from test, address comments
yarikbratashchuk Jun 16, 2022
a036585
Minor fixes and indentation in wat files
yarikbratashchuk Jun 21, 2022
3be772e
Update test for account_entrance_count
yarikbratashchuk Jun 21, 2022
5fdc100
Update reentrant_count_call test
yarikbratashchuk Jun 21, 2022
b656c88
Delegate call test
yarikbratashchuk Jun 23, 2022
17bb81f
Cargo +nightly fmt
yarikbratashchuk Jun 24, 2022
2f7f405
Address comments
yarikbratashchuk Jun 24, 2022
5f01797
Update reentrant_count_works test
yarikbratashchuk Jun 24, 2022
013e3bf
Merge branch 'master' into master
yarikbratashchuk Jun 24, 2022
3948142
Apply weights diff
yarikbratashchuk Jul 3, 2022
9c0c06f
Add fixture descriptions
yarikbratashchuk Jul 3, 2022
9c5bb47
Update comments as suggested
yarikbratashchuk Jul 3, 2022
35c0349
Update reentrant_count_call test to use seal_address
yarikbratashchuk Jul 3, 2022
1efdd1a
Merge remote-tracking branch 'paritytech/master' into feature/seal_re…
Artemka374 Nov 11, 2022
028f2ca
add missing code
Artemka374 Nov 11, 2022
2e07c7b
cargo fmt
Artemka374 Nov 11, 2022
b6e5084
account_entrance_count -> account_reentrance_count
Artemka374 Nov 14, 2022
fa02149
fix tests
Artemka374 Nov 14, 2022
fa4eef6
fmt
Artemka374 Nov 14, 2022
229a3ce
normalize signatures
Artemka374 Nov 14, 2022
4ac3bb3
Merge remote-tracking branch 'paritytech/master' into feature/seal_re…
Artemka374 Nov 14, 2022
a620843
Merge remote-tracking branch 'paritytech/master' into feature/seal_re…
Artemka374 Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cargo fmt
  • Loading branch information
yarikbratashchuk committed Jun 2, 2022
commit 72c8f83f8583e9f56587b1409252527870a37eb3
14 changes: 9 additions & 5 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ pub trait Ext: sealing::Sealed {
/// Sets new code hash for existing contract.
fn set_code_hash(&mut self, hash: CodeHash<Self::T>) -> Result<(), DispatchError>;

/// Returns then number of times currently executing contract exists on the call stack in addition
/// to the calling instance. A value of 0 means no reentrancy.
/// Returns then number of times currently executing contract exists on the call stack in
/// addition to the calling instance. A value of 0 means no reentrancy.
fn reentrant_count(&self) -> u32;

/// Returns the number of times specified contract exists on the call stack. Delegated calls are not
/// calculated as separate entrance.
/// Returns the number of times specified contract exists on the call stack. Delegated calls are
/// not calculated as separate entrance.
/// A value of 0 means it does not exist on the call stack.
fn account_entrance_count(&self, account_id: &AccountIdOf<Self::T>) -> u32;
}
Expand Down Expand Up @@ -1243,7 +1243,11 @@ where
}

fn account_entrance_count(&self, account_id: &AccountIdOf<Self::T>) -> u32 {
self.frames().filter_map(|f| (f.delegate_caller.is_none() && &f.account_id == account_id).then(|| true)).count() as u32
self.frames()
.filter_map(|f| {
(f.delegate_caller.is_none() && &f.account_id == account_id).then(|| true)
})
.count() as u32
}
}

Expand Down
8 changes: 4 additions & 4 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3257,8 +3257,8 @@ fn reentrant_count_works() {
AsRef::<[u8]>::as_ref(&contract_addr1).to_vec(),
true,
)
.result
.unwrap();
.result
.unwrap();
});
}
#[test]
Expand Down Expand Up @@ -3289,7 +3289,7 @@ fn account_entrance_count_works() {
AsRef::<[u8]>::as_ref(&contract_addr1).to_vec(),
true,
)
.result
.unwrap();
.result
.unwrap();
});
}
8 changes: 6 additions & 2 deletions frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,12 @@ mod tests {
fn ecdsa_to_eth_address(&self, _pk: &[u8; 33]) -> Result<[u8; 20], ()> {
Ok([2u8; 20])
}
fn reentrant_count(&self) -> u32 { 12 }
fn account_entrance_count(&self, _account_id: &AccountIdOf<Self::T>) -> u32 { unimplemented!() }
fn reentrant_count(&self) -> u32 {
12
}
fn account_entrance_count(&self, _account_id: &AccountIdOf<Self::T>) -> u32 {
unimplemented!()
}
}

fn execute<E: BorrowMut<MockExt>>(wat: &str, input_data: Vec<u8>, mut ext: E) -> ExecResult {
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@ define_env!(Env, <E: Ext>,
// Returns 0 when the contract does not exist on the call stack.
[__unstable__] seal_account_entrance_count(ctx, account_ptr: u32) -> u32 => {
ctx.charge_gas(RuntimeCosts::AccountEntranceCount)?;
let account_id: &<<E as Ext>::T as frame_system::Config>::AccountId = ctx.read_sandbox_memory_as(account_ptr)?;
let account_id: <<E as Ext>::T as frame_system::Config>::AccountId = ctx.read_sandbox_memory_as(account_ptr)?;
Ok(ctx.ext.account_entrance_count(&account_id) as u32)
},
);