fix: use flag-anchored positioning for MULTIPLE commission decode#26
Open
alphafitz11 wants to merge 1 commit intomainfrom
Open
fix: use flag-anchored positioning for MULTIPLE commission decode#26alphafitz11 wants to merge 1 commit intomainfrom
alphafitz11 wants to merge 1 commit intomainfrom
Conversation
The MULTIPLE commission parser previously used calldataHex.length to locate the middle block, which breaks when arbitrary data is appended after the commission data. Now derives middle block position from the flag index and validates referrerNum by trying each candidate (3-8). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Background
合约侧正在推进 ERC-8021 兼容性方案(docs/20260304-erc8021-compatibility/),核心变更是将 _getCommissionAndTrimInfo() 中的解析锚点从 calldatasize() 改为通过后向 flag 扫描定位的 effectiveEnd,以容忍 calldata 末尾拼接的任意长度后缀数据。
Decode 脚本需要同步适配:当 calldata 末尾存在额外数据时,解析不应依赖 calldata 总长度。
Problem
MULTIPLE commission 解析中,middle block 的定位使用了 calldataHex.length:
// 旧代码
const middleStart = calldataHex.length - (BYTE_SIZE.BLOCK * 2);
这假定 middle block 始终位于 calldata 倒数第二个 bytes32 位置。当 calldata 末尾拼接额外数据后,该偏移量指向错误位置,导致解析失败。
SINGLE/DUAL commission 和 SINGLE/DUAL trim 的解析已经是基于 flag 位置锚定的,不受影响。
Fix
改为基于 flag 位置向后推算 middle block:
Layout: [commissionN][commission_{N-1}]...[commission_2][middle][commission_1]
^flagIndex +64 ... +(N-2)*64 +(N-1)64 +N64
Test Plan