Skip to content

fix(prolink): keep leading zero bytes of call data and extraData - #430

Open
erkancamli wants to merge 1 commit into
base:masterfrom
erkancamli:fix/prolink-keep-calldata-bytes
Open

erkancamli wants to merge 1 commit into
base:masterfrom
erkancamli:fix/prolink-keep-calldata-bytes

Conversation

@erkancamli

Copy link
Copy Markdown

Summary

decodeProlink turned generic wallet_sendCalls call data and SpendPermission extraData into hex with bytesToHex, the integer formatter in utils/encoding.ts, which strips leading zero digits. These fields are raw bytes (EIP-8050: calldata as-is, extraData as "0x" + extra_data.hex()), so:

  • call data whose first hex digit is 0 comes back as odd length hex: approve(address,uint256) 0x095ea7b3… decodes to 0x95ea7b3…
  • call data that starts with a zero byte loses bytes: 0x00000000 decodes to 0x0
  • a SpendPermission with extraData 0x0001 decodes to 0x1, so the EIP-712 digest a wallet signs differs from the one the app built

The encoder is fine; only the decoder (decodeWalletSendCalls in shortcuts/sendCalls.ts, decodeWalletSign in shortcuts/sign.ts) is affected. This adds a rawBytesToHex helper (Hex.fromBytes, 0x for empty) and uses it for those two fields. Amount fields keep bytesToHex.

The salt and nonce fields have the same class of problem, but #395 already covers them, so they are left out here.

How did you test your changes?

New tests for the call data and extraData round trips, the helper, and an end-to-end encodeProlink → decodeProlink case with approve call data and 0x00000000. On master (1c31057) they fail (5 failed, 205 passed in prolink/); with this change all 210 pass.

In packages/account-sdk: yarn vitest --run passes (76 files, 1053 tests), yarn typecheck passes, and biome check is clean on the changed files. With 2000 random call data values through encode and decode, 133 changed on master and none with this change.

decodeProlink turned generic call data and SpendPermission extraData into
hex with bytesToHex, which strips leading zeros because it is meant for
integers. Call data that starts with a zero nibble, such as
approve(address,uint256) (0x095ea7b3), came back as odd length hex, and
data starting with a zero byte lost bytes (0x00000000 became 0x0).
A changed extraData also changes the SpendPermission digest a wallet signs.

Decode these raw bytes fields with a new rawBytesToHex helper that keeps
every byte, as EIP-8050 specifies for calldata and bytes values.
@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
1 if authored by an app that is not allowlisted and lacks verified human attribution 0
Sum 1

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants