What is the additional gas cost of the OpenZeppelin ReentrancyGuard?

Asked by idevelopthereforeiam on r/ethdev as a comment on a link to Reentrancy After Istanbul

https://www.reddit.com/r/ethdev/comments/dvg8hq/reentrancy_is_becoming_unavoidable_in/f7e9yd4
What is the additional gas cost of the OpenZeppelin ReentrancyGuard?

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 {
    }
}

@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.

The overhead should be 4 SLOAD, 5 if the compiler is not smart. SLOADs are being repriced from 200 to 800 however, so I'd expect ~3.5k gas.

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?