Skip to content

Commit ae7d21f

Browse files
authored
Remove leading zeros from signature r and s (#173)
1 parent 87e9132 commit ae7d21f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Bug Fixes
6+
7+
- Remove leading zeros from signature r and s values
8+
39
## v0.6.0 (2025-01-01)
410

511
### Breaking Changes

lib/ethers/transaction/signed.ex

+7-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ defmodule Ethers.Transaction.Signed do
160160
end
161161

162162
defimpl Transaction.Protocol do
163+
import Ethers.Utils, only: [remove_leading_zeros: 1]
164+
163165
def type_id(signed_tx), do: Transaction.Protocol.type_id(signed_tx.pyalod)
164166

165167
def type_envelope(signed_tx), do: Transaction.Protocol.type_envelope(signed_tx.payload)
@@ -171,7 +173,11 @@ defmodule Ethers.Transaction.Signed do
171173
end
172174

173175
defp signature_fields(signed_tx) do
174-
[signed_tx.signature_y_parity_or_v, signed_tx.signature_r, signed_tx.signature_s]
176+
[
177+
signed_tx.signature_y_parity_or_v,
178+
remove_leading_zeros(signed_tx.signature_r),
179+
remove_leading_zeros(signed_tx.signature_s)
180+
]
175181
end
176182
end
177183
end

lib/ethers/utils.ex

+7
Original file line numberDiff line numberDiff line change
@@ -540,4 +540,11 @@ defmodule Ethers.Utils do
540540
raise ArgumentError, "Invalid Ethereum address binary #{inspect(address)}"
541541
end
542542
end
543+
544+
@doc """
545+
Removes leading zeros from a binary.
546+
"""
547+
@spec remove_leading_zeros(binary()) :: binary()
548+
def remove_leading_zeros(<<0, rest::binary>>), do: remove_leading_zeros(rest)
549+
def remove_leading_zeros(bin) when is_binary(bin), do: bin
543550
end

0 commit comments

Comments
 (0)