-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add gas overhead per word to wrapper #12669
Conversation
I see you updated files related to |
I see you updated files related to |
@@ -84,6 +84,7 @@ contract VRFV2PlusWrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsume | |||
// s_wrapperGasOverhead reflects the gas overhead of the wrapper's fulfillRandomWords | |||
// function. The cost for this gas is passed to the user. | |||
uint32 private s_wrapperGasOverhead; | |||
uint16 private s_wrapperGasOverheadPerWord; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is only 7 gas units per word, we probably don't need it right? we can just add some extra buffer to s_wrapperGasOverhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, if my calculation is correct and the overhead is that small then we can just add some buffer for it. It's at most 2.5k more gas if it's 10 gas per word. I'll need to run more transactions.
Please run |
Quality Gate passedIssues Measures |
uint256[] memory randomWords
touint256[] calldata randomWords
ascalldata
is cheaper. (around 200 to 300 less gas from forge test)Currently the wrapper overheads are a fix cost so it doesn't matter if you are requesting 0 word, 1 word, or a maximum of 255 words; they cost the same.
The wrapper gas overhead per word isn't that much and is mostly attributed to just copying the
randomWords
array around. Rough estimation works out to be around 7 gas per word.The coordinator gas overhead per word is much more expensive and works out to be around 440 gas per word. Other than copying around the
randomWords
array, there's actual work done in generating the random word.This 440 gas per word (calculated by making a transaction with 0 num words, a transaction with 255 num words, take the difference and divide by 255) isn't too implausible as well because a quick forge test calculates that line to be around 232 to 235 gas.
Whereas the gas used before and after the loop works out to be around 333 gas per loop