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

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

Calling a function (doStuffNonReentrant) with the nonReentrant modifier
Gas Used by Transaction: 28,655

28,655 - 21,208 = 7,447 gas overhead


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

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

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?