You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To prevent developers from making reentrancy vulnerabilities in the contract ink! doesn't allow reentrancy during cross-contract calls by default. It is controlled via CallFlags.allow_reentry(false by default) during the creation of a cross-contract call(CallBuilder).
/// The flags used to change the behavior of a contract call.#[must_use]#[derive(Copy,Clone,Debug,Default)]pubstructCallFlags{forward_input:bool,clone_input:bool,tail_call:bool,allow_reentry:bool,}
If the contract already exists in the stack of calls, the contract-pallet immediately finishes executing the transaction and throws the ReentranceDenied error. The caller contract can't handle it, and it is hard to debug(discussion). Also, with that workflow, we can't have some functions that allow reentrancy and some that deny it.
To improve the usability and add control on which methods accept reentrancy and which do not, we want to introduce a new modifier for the message allow_reentrancy and change the default behavior of the CallFlags.
A new definition looks like:
/// The flags used to change the behavior of a contract call.#[must_use]#[derive(Copy,Clone,Debug,Default)]pubstructCallFlags{forward_input:bool,clone_input:bool,tail_call:bool,deny_reentry:bool,// reverse behavior}
So it is a breaking change because the allow_reentry function will be renamed to deny_reentry(We can keep empty allow_reentry, but better inform all users about the new API).
The allow_reentrancy behaves as a payable modifier but checks the output of seal_reentrant_count. All methods don't allow reentrancy by default. But the developer can mark some methods with the allow_reentrancy modifier to allow it.
/// Transfers `amount` from caller to `to`.#[ink(message, allow_reentrancy)]fntransfer(&mutself,to:AccountId,amount:Balance);
The implementation in codegen is the same as for payable so we need only repeat the logic.
The text was updated successfully, but these errors were encountered:
Are we okay with a new API and behavior? The level of security is the same. The caller contract controls the reentrancy during the execution of the cross-contract call(if we enter again into the same contract) than during instantiating the cross-contract call.
To prevent developers from making reentrancy vulnerabilities in the contract ink! doesn't allow reentrancy during cross-contract calls by default. It is controlled via
CallFlags.allow_reentry
(false by default) during the creation of a cross-contract call(CallBuilder
).If the contract already exists in the stack of calls, the
contract-pallet
immediately finishes executing the transaction and throws theReentranceDenied
error. The caller contract can't handle it, and it is hard to debug(discussion). Also, with that workflow, we can't have some functions that allow reentrancy and some that deny it.To improve the usability and add control on which methods accept reentrancy and which do not, we want to introduce a new modifier for the message
allow_reentrancy
and change the default behavior of theCallFlags
.A new definition looks like:
So it is a breaking change because the
allow_reentry
function will be renamed todeny_reentry
(We can keep emptyallow_reentry
, but better inform all users about the new API).The
allow_reentrancy
behaves as apayable
modifier but checks the output ofseal_reentrant_count
. All methods don't allow reentrancy by default. But the developer can mark some methods with theallow_reentrancy
modifier to allow it.The implementation in codegen is the same as for
payable
so we need only repeat the logic.The text was updated successfully, but these errors were encountered: