The Reentrancy library provides an API to check for and disallow reentrancy on a contract.
More information can be found in the specification.
While this can protect against both single-function reentrancy and cross-function reentrancy attacks, it WILL NOT PREVENT a cross-contract reentrancy attack.
Once imported, using the Reentrancy Library can be done by calling one of the two functions. For more information, see the specification.
is_reentrant() -> bool
reentrancy_guard()
The reentrancy_guard
function asserts is_reentrant()
returns false.
use reentrancy::reentrancy_guard;
abi MyContract {
fn my_non_reentrant_function();
}
impl MyContract for Contract {
fn my_non_reentrant_function() {
reentrancy_guard();
// my code here
}
}