I tried using the nonReentrant
modifier on a test contract on Ropsten and got a 7,447 gas overhead.
Calling a function (doStuff
)
Gas Used by Transaction: 21,208
https://ropsten.etherscan.io/tx/0x722f698f708fcdd1b435d5b12f845b13cf61794deb2b8c2e7e9aae4ab52e1ba5
Calling a function (doStuffNonReentrant
) with the nonReentrant
modifier
Gas Used by Transaction: 28,655
https://ropsten.etherscan.io/tx/0x6d8cd74637ae08706691a95c3f359b39353a4421672ac46089ff503861745225
28,655 - 21,208 = 7,447 gas overhead
Test.sol
pragma solidity ^0.5.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.4.0/contracts/utils/ReentrancyGuard.sol";
contract Test is ReentrancyGuard {
function doStuff() public {
}
function doStuffNonReentrant() public nonReentrant {
}
}
1 Like
frangio
November 14, 2019, 3:15pm
3
@nventuro and @DericEcourcy recently revamped ReentrancyGuard
to be cheaper when the upcoming net gas metering lands.
They may have some insights into what the gas costs will be with this change.
OpenZeppelin:master
← ericDeCourcy:patch-1
opened 10:00PM - 12 Nov 19 UTC
2 Likes
The overhead should be 4 SLOAD
, 5 if the compiler is not smart. SLOAD
s are being repriced from 200 to 800 however, so I'd expect ~3.5k gas.
1 Like
Hi @nventuro ,
Is there a better way to test the overhead, as I got a larger figure than ~3.5k?
did you find an alternative here?