Skip to content

Commit 7322730

Browse files
authored
Merge pull request ethereum#14604 from bas-vk/mobile-getfrom
mobile: use EIP155 signer for determining sender
2 parents 061889d + b8793ed commit 7322730

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

mobile/android_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ package go;
3737
import android.test.InstrumentationTestCase;
3838
import android.test.MoreAsserts;
3939
40+
import java.math.BigInteger;
41+
import java.util.Arrays;
42+
4043
import org.ethereum.geth.*;
4144
4245
public class AndroidTest extends InstrumentationTestCase {
@@ -115,6 +118,32 @@ public class AndroidTest extends InstrumentationTestCase {
115118
fail(e.toString());
116119
}
117120
}
121+
122+
// Tests that recovering transaction signers works for both Homestead and EIP155
123+
// signatures too. Regression test for go-ethereum issue #14599.
124+
public void testIssue14599() {
125+
try {
126+
byte[] preEIP155RLP = new BigInteger("f901fc8032830138808080b901ae60056013565b6101918061001d6000396000f35b3360008190555056006001600060e060020a6000350480630a874df61461003a57806341c0e1b514610058578063a02b161e14610066578063dbbdf0831461007757005b610045600435610149565b80600160a060020a031660005260206000f35b610060610161565b60006000f35b6100716004356100d4565b60006000f35b61008560043560243561008b565b60006000f35b600054600160a060020a031632600160a060020a031614156100ac576100b1565b6100d0565b8060018360005260205260406000208190555081600060005260206000a15b5050565b600054600160a060020a031633600160a060020a031614158015610118575033600160a060020a0316600182600052602052604060002054600160a060020a031614155b61012157610126565b610146565b600060018260005260205260406000208190555080600060005260206000a15b50565b60006001826000526020526040600020549050919050565b600054600160a060020a031633600160a060020a0316146101815761018f565b600054600160a060020a0316ff5b561ca0c5689ed1ad124753d54576dfb4b571465a41900a1dff4058d8adf16f752013d0a01221cbd70ec28c94a3b55ec771bcbc70778d6ee0b51ca7ea9514594c861b1884", 16).toByteArray();
127+
preEIP155RLP = Arrays.copyOfRange(preEIP155RLP, 1, preEIP155RLP.length);
128+
129+
byte[] postEIP155RLP = new BigInteger("f86b80847735940082520894ef5bbb9bba2e1ca69ef81b23a8727d889f3ef0a1880de0b6b3a7640000802ba06fef16c44726a102e6d55a651740636ef8aec6df3ebf009e7b0c1f29e4ac114aa057e7fbc69760b522a78bb568cfc37a58bfdcf6ea86cb8f9b550263f58074b9cc", 16).toByteArray();
130+
postEIP155RLP = Arrays.copyOfRange(postEIP155RLP, 1, postEIP155RLP.length);
131+
132+
Transaction preEIP155 = new Transaction(preEIP155RLP);
133+
Transaction postEIP155 = new Transaction(postEIP155RLP);
134+
135+
preEIP155.getFrom(null); // Homestead should accept homestead
136+
preEIP155.getFrom(new BigInt(4)); // EIP155 should accept homestead (missing chain ID)
137+
postEIP155.getFrom(new BigInt(4)); // EIP155 should accept EIP 155
138+
139+
try {
140+
postEIP155.getFrom(null);
141+
fail("EIP155 transaction accepted by Homestead");
142+
} catch (Exception e) {}
143+
} catch (Exception e) {
144+
fail(e.toString());
145+
}
146+
}
118147
}
119148
`
120149

mobile/types.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,11 @@ func (tx *Transaction) GetHash() *Hash { return &Hash{tx.tx.Hash()} }
264264
func (tx *Transaction) GetSigHash() *Hash { return &Hash{tx.tx.SigHash(types.HomesteadSigner{})} }
265265
func (tx *Transaction) GetCost() *BigInt { return &BigInt{tx.tx.Cost()} }
266266

267-
func (tx *Transaction) GetFrom() (address *Address, _ error) {
268-
from, err := types.Sender(types.HomesteadSigner{}, tx.tx)
267+
func (tx *Transaction) GetFrom(chainID *BigInt) (address *Address, _ error) {
268+
if chainID == nil { // Null passed from mobile app
269+
chainID = new(BigInt)
270+
}
271+
from, err := types.Sender(types.NewEIP155Signer(chainID.bigint), tx.tx)
269272
return &Address{from}, err
270273
}
271274

0 commit comments

Comments
 (0)