ReentrancyGuard vs ReentrancyGuardTransient gas saving

I think I found the answer here: What is the gas overhead of ReentrancyGuard? - #6 by frangio

It is because of the 2800 refund at the second SSTORE.

So the correct breakdown is this:

ReentrancyGuard.nonReentrant gas usage:

  1. SLOAD 2100 gas (status == 2)
  2. SSTORE 2900 gas (status 2)
  3. SSTORE 100 gas and refunds 2800 (status 1)

ReentrancyGuardTransient.nonReentrant gas usage:

  1. TLOAD 100 gas (status == 2)
  2. TSTORE 100 gas (status 2)
  3. TSTORE 100 gas (status 1)

it's 2300 vs 300 gas so the 2000 gas saving checks out

1 Like