go-ethereum/accounts/abi
cuiweixie 39a9e49233 accounts/abi: copy selector in Pack to avoid aliasing cached method.ID
ABI.Pack returned `append(method.ID, arguments...)`. method.ID is derived
from crypto.Keccak256(sig)[:4], which yields a slice of length 4 but
capacity 32 (the full keccak hash buffer), and it is computed once and
cached on the parsed method. When a method takes no arguments, the append
has nothing to copy and returns method.ID's own backing array.

The caller therefore received calldata that aliased the ABI's cached
selector. Mutating that calldata, or a concurrent Pack of the same no-arg
method, corrupted the cached selector and broke every subsequent encode
of that method. (Methods with arguments always pack to >=32 bytes, so
4+32 > 32 forces a reallocation and they were never affected.)

Copy method.ID into a fresh slice before appending the arguments so the
returned calldata never shares storage with the cached selector. Add a
regression test that packs a no-arg method, mutates the result, and
verifies both the cached selector and a subsequent pack are unaffected.
2026-06-11 20:00:00 +08:00
..
abigen cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
bind all: fix all typos, as reported by crates-ci/typos (#35008) 2026-06-10 18:50:51 +02:00
abi.go accounts/abi: copy selector in Pack to avoid aliasing cached method.ID 2026-06-11 20:00:00 +08:00
abi_test.go accounts/abi: support unpacking solidity errors (#30738) 2024-12-10 14:30:24 +01:00
abifuzzer_test.go accounts: run tests in parallel (#28544) 2023-12-04 14:55:06 +01:00
argument.go accounts/abi: fix wrong want count for events (#35077) 2026-05-29 22:27:11 +02:00
doc.go all: fix license headers one more time 2015-07-23 18:35:11 +02:00
error.go accounts/abi: context info on unpack-errors (#28529) 2023-11-21 09:16:57 +01:00
error_handling.go accounts/abi: error when packing negative values in unsigned types (#31790) 2025-06-04 14:47:01 +02:00
event.go accounts/abi/bind: fix duplicate field names in the generated go struct (#24924) 2022-06-07 08:38:54 +02:00
event_test.go build: update to golangci-lint 1.61.0 (#30587) 2024-10-14 19:25:22 +02:00
method.go accounts/abi: improve readability of method-to-string conversion (#28530) 2023-11-15 14:30:35 +01:00
method_test.go accounts: run tests in parallel (#28544) 2023-12-04 14:55:06 +01:00
pack.go accounts/abi: error when packing negative values in unsigned types (#31790) 2025-06-04 14:47:01 +02:00
pack_selector_alias_test.go accounts/abi: copy selector in Pack to avoid aliasing cached method.ID 2026-06-11 20:00:00 +08:00
pack_test.go accounts/abi: error when packing negative values in unsigned types (#31790) 2025-06-04 14:47:01 +02:00
packing_test.go accounts/abi: ABI explicit difference between Unpack and UnpackIntoInterface (#21091) 2020-09-28 14:10:26 +02:00
reflect.go accounts/abi, accounts/keystore: use reflect.TypeFor (#32323) 2025-08-11 14:24:55 +02:00
reflect_test.go accounts/abi, accounts/keystore: use reflect.TypeFor (#32323) 2025-08-11 14:24:55 +02:00
selector_parser.go accounts/abi: array-parse error reports the wrong character (#35106) 2026-06-08 12:00:30 +02:00
selector_parser_test.go accounts: run tests in parallel (#28544) 2023-12-04 14:55:06 +01:00
topics.go accounts/abi: fix MakeTopics mutation of big.Int inputs (#30785) 2024-11-25 13:34:50 +01:00
topics_test.go accounts/abi: fix MakeTopics mutation of big.Int inputs (#30785) 2024-11-25 13:34:50 +01:00
type.go accounts/abi, accounts/keystore: use reflect.TypeFor (#32323) 2025-08-11 14:24:55 +02:00
type_test.go all: fix various typos (#29600) 2024-04-23 13:09:42 +03:00
unpack.go accounts/abi: forEachUnpack ABI error message arguments swapped (#35046) 2026-05-26 10:29:00 +02:00
unpack_test.go accounts/abi: fix unittest code (#34740) 2026-05-12 08:50:04 -04:00
utils.go build: upgrade to go 1.19 (#25726) 2022-09-10 13:25:40 +02:00