So I tried to check how much gas I can save if I use ReentrancyGuardTransient instead of ReentrancyGuard and for most of the tests it seems like it's around ~2000 gas or less. Based on my understanding this should be a little more, considering the fact that ReentrancyGuard is writing into an already existing storage slot, so I would assume it should be around ~5000 gas saved.
In theory gas usage should be something like this:
ReentrancyGuard.nonReentrant gas usage:
SLOAD 2100 gas (status == 2)
SSTORE 2900 gas (status 2)
SSTORE 100 gas (status 1)
ReentrancyGuardTransient.nonReentrant gas usage:
TLOAD 100 gas (status == 2)
TSTORE 100 gas (status 2)
TSTORE 100 gas (status 1)
May I ask what is the reason for this? Is it because of TransientSlot is being used?
Code to reproduce
I created a small repo where this can be reproduced and here are the actual gas snapshots.
As far as I can see it is simply to use this kind of transient
variable with cheaper storage cost. But the saving is significant? we are talking about a variable of type value.