Skip to content

Commit 15f0285

Browse files
authored
Turn U256::from to U256::from_big_endian (#946)
Fixes @nlordell comment on #944 I don't think it's worth releasing a version with this, as the U256 from bytes documentation ensures it's always interpreted as big endian: https://docs.rs/uint/latest/src/uint/uint.rs.html#1363 ### Test Plan KMS example still works
1 parent 9560f91 commit 15f0285

File tree

1 file changed

+4
-4
lines changed
  • ethcontract/src/transaction

1 file changed

+4
-4
lines changed

ethcontract/src/transaction/kms.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ impl Account {
9898
r.0.copy_from_slice(&compact[..32]);
9999

100100
// If `s` happens to be "on the dark side of the curve", we need to invert it (EIP-2)
101-
let mut s_tentative: U256 = U256::from(&compact[32..]);
102-
let secp256k1_n = U256::from(CURVE_ORDER);
101+
let mut s_tentative: U256 = U256::from_big_endian(&compact[32..]);
102+
let secp256k1_n = U256::from_big_endian(&CURVE_ORDER);
103103
if s_tentative > secp256k1_n / 2 {
104104
s_tentative = secp256k1_n - s_tentative;
105105
}
@@ -162,8 +162,8 @@ impl Account {
162162
encoder.append(&v);
163163
// RLP encoding doesn't allow leading zeros for s & r, yet default H256 RLP encoding preserves leading 0s
164164
// By converting and encoding U256, we get rid of the leading zeros.
165-
encoder.append(&U256::from(signature.r.as_bytes()));
166-
encoder.append(&U256::from(signature.s.as_bytes()));
165+
encoder.append(&U256::from_big_endian(signature.r.as_bytes()));
166+
encoder.append(&U256::from_big_endian(signature.s.as_bytes()));
167167

168168
let raw_transaction = Bytes(match id {
169169
Some(id) => [&[id], encoder.as_raw()].concat(),

0 commit comments

Comments
 (0)