feat: add packed calldata update for ~24% calldata savings#265
feat: add packed calldata update for ~24% calldata savings#265TuDo1403 wants to merge 2 commits intoStork-Oracle:mainfrom
Conversation
Add LibCodec library that packs TemporalNumericValueInput into a flat uint256[] with 6 words per entry (vs ~9 ABI-encoded words). Packs v flag, timestampNs, and quantizedValue into a single word with zero wasted bits. - Add updateTemporalNumericValuesV1Packed(uint256[]) entry point - Add compress() helper for off-chain struct-to-packed conversion - Extract shared verify+update logic into _verifyAndUpdate() - Add Foundry fuzz tests for encode/decode roundtrip correctness
akawalsky
left a comment
There was a problem hiding this comment.
Great work - left a few comments. Going to get a review from @harryrackmil as well.
| uint256 len = inputs.length; | ||
| words = new uint256[](len * WORDS_PER_ENTRY); | ||
|
|
||
| for (uint256 i; i < len; ++i) { |
There was a problem hiding this comment.
Lets add an invariant to this loop to ensure timestampNs is actually 63 bits. Practically speaking we should be safe but it would be good to make this future proof (at least until 2262)
There was a problem hiding this comment.
Let's bump the version in this file to 1.0.6. That way our pusher will be able to easily determine which function to use.
This will require small test changes in UpgradeableStork.ts
| function updateTemporalNumericValuesV1( | ||
| StorkStructs.TemporalNumericValueInput[] calldata updateData | ||
| ) public payable { | ||
| _verifyAndUpdate(updateData); |
There was a problem hiding this comment.
Worth noting that converting this calldata to memory will have some gas impact on this function call, but should be negligible compared to signature recovery. Overall I'm fine encouraging the newer method in favor of code simplification.
- add 63-bit timestampNs overflow check in LibCodec.encode - bump version to 1.0.6 - convert Foundry tests to Hardhat TypeScript, remove foundry.toml - assert exact 640-byte savings in calldata size test - fix comment: 6 words per entry, not 7
Summary
LibCodeclibrary that packsTemporalNumericValueInputinto a flatuint256[]with 6 words per entry, packingvflag (1 bit),timestampNs(63 bits), andquantizedValue(192 bits) into a single word with zero wasted bitsTest plan