-
Notifications
You must be signed in to change notification settings - Fork 4
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
assembly-optimization-in-digestFromCid+customRevertErrors #48
base: main
Are you sure you want to change the base?
Conversation
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.
Remove .DS_Store please
@@ -11,6 +11,21 @@ contract PDPService { | |||
uint256 public constant LEAF_SIZE = 32; | |||
uint256 public constant MAX_ROOT_SIZE = 1 << 50; | |||
|
|||
// Errors | |||
error ProofSetNotLive(); |
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.
Im not convinced that this is really saving much gas. And including them is adding to contract size and cluttering the code. The benchmarks that show improvement are all tests that revert. Can you please run the benchmarks again separately for the two optimizations so we can see exactly which contributes to which savings?
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.
The custom error change should be in a different commit from the cid digest optimization
// // Copy 32 bytes (one word) from dataStart into dataSlice. | ||
// mstore(dataSlice, mload(dataStart)) | ||
assembly { | ||
// Get the pointer to the cid.data bytes array |
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.
This piece looks great, thank you
Gas Usage Comparison for Smart Contract Tests
This document compares gas usage between the previous and updated versions of the smart contracts, focusing on assembly optimizations for
cidToDigest
and the use of custom errors to save gas.Summary of Gas Savings
Analysis
The updated version shows better gas efficiency for most tests, especially those involving error handling and proof validation. Using custom errors reduced gas consumption, particularly where error strings were previously loaded.
However, a few tests have slightly increased gas usage.
Notable Gas Savings
cidToDigest
.Areas for Improvement
Conclusion
Optimizing
cidToDigest
with assembly and using custom errors led to some gas savings. Some areas still have room for improvement where gas usage increased slightly. Overall, the updates improved contract efficiency.