[Enhancement] Optimize CairoLib Functions by Overloading with calldata
for Gas Efficiency
#11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces optimizations to the
CairoLib.sol
library by overloading functions to acceptcalldata
parameters instead ofmemory
. These changes aim to enhance gas efficiency when interacting with Cairo contracts on Starknet.Changes Introduced
Function Overloading with
calldata
:callCairo
,staticcallCairo
, andmulticallCairo
functions that acceptcalldata
parameters.memory
parameter functions to ensure backward compatibility.Code Adjustments:
abi.encode
) to handle bothmemory
andcalldata
inputs effectively.Rationale
Overloading functions with
calldata
parameters can lead to significant gas savings by eliminating unnecessary data copying into memory, especially for functions that do not modify input data. This optimization aligns with the feature request outlined in #8 and enhances the efficiency of interactions between Solidity and Cairo contracts.Considerations
memory
parameters are retained to prevent breaking existing integrations.string
data locations to prevent compiler resolution issues.Related Issue #8
Additional Notes
I understand that this contribution was not explicitly requested. However, considering the nature of the issue and the potential benefits of the proposed optimizations, I wanted to offer this solution. I'm open to feedback and willing to make further adjustments to better align with the project's goals and standards.
Please feel free to review the changes and let me know if there are any areas that require modification or additional testing. I'm eager to contribute and support the project's development in any way I can.
Checklist
Thank you for considering my contribution!