# Calculate ReentrancyGuard Modifier

Does anyone know how to effectively calculate the cost of adding in a ReentrancyGuard modifier onto a function. There have been discussions where a gas refund is issued as the original state is returned in the same transaction. 1 --> 2 --> 1.
However due to the later EIPs, some refund issuance has been removed.

EIP 3529 states these value changes cost 212 gas, and since the reentrancy access a state variable when cold, 2100 is added, so roughly 2312 gas is totalled.

Here's a thread on updating the modifier for more efficient gas usage: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1992

Testing on Remix with and without a modifier results in an average of 2400 gas added with the modifier.

`gasleft()` returns the gas remaining. it can be used to do some measurements by isolating the thing you want to measure. got a difference of 2167 gas for the modifier in the contract below

``````pragma solidity ^0.8.0;

contract GasAccounting {
uint256 public myValue;

constructor() {
owner = msg.sender;
}

function myFunc(uint256 value) public {
myValue = value;
}

modifier onlyOwner {
require(msg.sender == owner, "Not the owner");
_;
}

function myFuncWithModifier(uint256 value) public onlyOwner {
myFunc(value);
}

function myFuncWithoutModifier(uint256 value) public {
myFunc(value);
}

event GasSpent(uint256 gasSpent);

function measureWithModifier(uint256 value) external {
uint256 g = gasleft();
myFuncWithModifier(value);
emit GasSpent(g - gasleft());
}

function measureWithoutModifier(uint256 value) external {
uint256 g = gasleft();
myFuncWithoutModifier(value);
emit GasSpent(g - gasleft());
}
}
``````

This isn't really what I'm looking for. This is trivial to replicate but the problem is understanding the OPCODEs executed and the calculation of gas performed. There are many EIPs which outdate previous assumptions of gas refunds and SSTORE costs.

A common one is where 0 --> 1 --> 0 would cost 20, 000 store for a zero to non zero value change, then a 15, 000 refund for setting back to zero, totaling 5, 000 Gas. This is not the case anymore.