danielmcclure / bitcoinj

Automatically exported from code.google.com/p/bitcoinj
Apache License 2.0
0 stars 1 forks source link

Wallet can throw incorrect exception when password is wrong #585

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This was detected by the unit tests and makes the behaviour flaky. The 
assertion is checking that downward key derivation worked correctly. If the AES 
padding happens to be the correct value then we'll hit this and throw 
IllegalStateException instead of KeyCrypterException.

10:01:26 10 MnemonicCode.toSeed: PBKDF2 took 21ms
10:01:26 10 KeyChainGroup.addAndActivateHDChain: Creating and activating a new 
HD chain: org.bitcoinj.wallet.DeterministicKeyChain@852730b
10:01:26 10 DeterministicKeyChain.maybeLookAhead: 1 keys needed for M/0H/0 = 1 
issued + 0 lookahead size + 0 lookahead threshold - 0 num children
10:01:26 10 DeterministicKeyChain.maybeLookAhead: Took 1 msec
10:01:26 10 AbstractBlockChain.<init>: chain head is at height 0:
v1 block: 
   previous block: 0000000000000000000000000000000000000000000000000000000000000000
   merkle root: 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
   time: [1414008045] Wed Oct 22 22:00:45 CEST 2014
   difficulty target (nBits): 545259519
   nonce: 5

10:01:26 10 MnemonicCode.toSeed: PBKDF2 took 21ms
10:01:26 10 KeyChainGroup.addAndActivateHDChain: Creating and activating a new 
HD chain: org.bitcoinj.wallet.DeterministicKeyChain@13838550
10:01:26 10 DeterministicKeyChain.maybeLookAhead: 1 keys needed for M/0H/0 = 1 
issued + 0 lookahead size + 0 lookahead threshold - 0 num children
10:01:26 10 DeterministicKeyChain.maybeLookAhead: Took 1 msec
10:01:26 10 Wallet.receivePending: Received a pending transaction 
624254eb2409ebdd6c6a2b648346c2a8e7d395b5721e880a8d67ae720eba9d4b that spends 
0.00 BTC from our own wallet, and sends us 1.00 BTC
10:01:26 10 Wallet.receivePending: Wallet received transaction with an unknown 
source. Consider tagging it!
10:01:26 10 Wallet.maybeCommitTx: commitTx of 
624254eb2409ebdd6c6a2b648346c2a8e7d395b5721e880a8d67ae720eba9d4b
10:01:26 10 Wallet.maybeCommitTx: ->pending: 
624254eb2409ebdd6c6a2b648346c2a8e7d395b5721e880a8d67ae720eba9d4b
10:01:26 10 Wallet.receive: Received tx for 1.00 BTC: 
624254eb2409ebdd6c6a2b648346c2a8e7d395b5721e880a8d67ae720eba9d4b [0] in block 
7302e0584f768c41e916d605f542f87ed3175fa92afcbec2c6e7033489871cb8
10:01:26 10 Wallet.receive:   <-pending
10:01:26 10 Wallet.processTxFromBestChain:   tx 
624254eb2409ebdd6c6a2b648346c2a8e7d395b5721e880a8d67ae720eba9d4b ->unspent
10:01:26 10 Wallet.receive: Balance is now: 1.00 BTC
10:01:26 10 Wallet.completeTx: Completing send tx with 1 outputs totalling 
10.00 BTC (not including fees)
10:01:26 10 Wallet.calculateFee: Insufficient value in wallet for send: needed 
9.00 BTC more
10:01:26 10 Wallet.completeTx: Completing send tx with 1 outputs totalling 0.50 
BTC (not including fees)
10:01:26 10 DeterministicKeyChain.maybeLookAhead: 1 keys needed for M/0H/1 = 1 
issued + 0 lookahead size + 0 lookahead threshold - 0 num children
10:01:26 10 DeterministicKeyChain.maybeLookAhead: Took 0 msec
10:01:26 10 Wallet.completeTx:   with 0.49 BTC change
10:01:26 10 Wallet.completeTx: Completing send tx with 1 outputs totalling 0.50 
BTC (not including fees)
10:01:26 10 Wallet.completeTx:   with 0.49 BTC change

java.lang.IllegalStateException
    at com.google.common.base.Preconditions.checkState(Preconditions.java:161)
    at org.bitcoinj.crypto.DeterministicKey.derivePrivateKeyDownwards(DeterministicKey.java:296)
    at org.bitcoinj.crypto.DeterministicKey.findOrDeriveEncryptedPrivateKey(DeterministicKey.java:271)
    at org.bitcoinj.crypto.DeterministicKey.decrypt(DeterministicKey.java:242)
    at org.bitcoinj.crypto.DeterministicKey.decrypt(DeterministicKey.java:40)
    at org.bitcoinj.core.ECKey.decrypt(ECKey.java:1001)
    at org.bitcoinj.crypto.DeterministicKey.decrypt(DeterministicKey.java:253)
    at org.bitcoinj.crypto.DeterministicKey.decrypt(DeterministicKey.java:40)
    at org.bitcoinj.wallet.DecryptingKeyBag.maybeDecrypt(DecryptingKeyBag.java:50)
    at org.bitcoinj.wallet.DecryptingKeyBag.findKeyFromPubHash(DecryptingKeyBag.java:67)
    at org.bitcoinj.core.TransactionOutPoint.getConnectedRedeemData(TransactionOutPoint.java:175)
    at org.bitcoinj.core.TransactionInput.getConnectedRedeemData(TransactionInput.java:315)
    at org.bitcoinj.core.Wallet.signTransaction(Wallet.java:3488)
    at org.bitcoinj.core.Wallet.completeTx(Wallet.java:3419)
    at org.bitcoinj.core.WalletTest.basicSpendingCommon(WalletTest.java:325)
    at org.bitcoinj.core.WalletTest.basicSpendingWithEncryptedWallet(WalletTest.java:145)

10:01:35 433 NioClientManager.handleKey: Successfully connected to 
localhost/127.0.0.1:4243
10:01:46 10 MnemonicCode.toSeed: PBKDF2 took 21ms
10:01:46 10 KeyChainGroup.addAndActivateHDChain: Creating and activating a new 
HD chain: org.bitcoinj.wallet.DeterministicKeyChain@38ac93db
10:01:46 10 DefaultRiskAnalysis.isStandard: TX considered non-standard due to 
output 0 violating rule DUST

Process finished with exit code 255

Original issue reported on code.google.com by mh.in.en...@gmail.com on 22 Oct 2014 at 8:06

GoogleCodeExporter commented 9 years ago
Any idea how high is the chance to hit this, given a random key of course.

Original comment by andreas....@gmail.com on 22 Oct 2014 at 8:13

GoogleCodeExporter commented 9 years ago
Not that high but high enough that it needs to be fixed. I think it's probably 
something like 1:256 but it might be higher, perhaps 1:66536

Original comment by mh.in.en...@gmail.com on 22 Oct 2014 at 8:20