linera-protocol icon indicating copy to clipboard operation
linera-protocol copied to clipboard

Decide if reentrancy can be allowed for certain VMs

Open ma2bd opened this issue 7 months ago • 3 comments

ma2bd avatar Apr 29 '25 15:04 ma2bd

Or certain apps? This could conceivably be part of the application description

MathieuDutSik avatar Apr 30 '25 06:04 MathieuDutSik

Reentrancy is used in some DeFi applications for Flash loans. The code for the provider will look like this:

function flashLoan(address receiver, uint256 amount, bytes calldata data) external {
    uint256 balanceBefore = address(this).balance;
    (bool ok, ) = receiver.call{ value: amount }(
        abi.encodeWithSignature("executeOperation(uint256,bytes)", amount, data)
    );
    require(ok, "callback failed");
    require(address(this).balance >= balanceBefore + fee, "loan not repaid");
}

So, you call your lending protocol (Uniswap, Morpho, etc.) with your callback information, and it does a reentrant call on your contract and checks that it went correctly. The operation is done completely or not at all.

MathieuDutSik avatar Apr 30 '25 07:04 MathieuDutSik

Or certain apps? This could conceivably be part of the application description

Yes, technically it should be very easy to have two Ethereum VM configurations: one with reentrancy and one without.

ma2bd avatar Apr 30 '25 09:04 ma2bd