Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error at BitcoinJ deserializing message #2557

Closed
ManfredKarrer opened this issue Mar 18, 2019 · 3 comments
Closed

Error at BitcoinJ deserializing message #2557

ManfredKarrer opened this issue Mar 18, 2019 · 3 comments
Assignees

Comments

@ManfredKarrer
Copy link
Member

Running dao-betanet (mainnet) I got that error msg repeatadly.
@oscarguindzberg Any idea? Can it be that some new data is not supported by the PB serialisation in our branch?

org.bitcoinj.core.ProtocolException: Error deserializing message f9beb4d9616c65727400000000000000a80000001bf9aaea60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50

at org.bitcoinj.core.BitcoinSerializer.deserializePayload(BitcoinSerializer.java:185)
at org.bitcoinj.core.BitcoinSerializer.deserialize(BitcoinSerializer.java:146)
at org.bitcoinj.core.PeerSocketHandler.receiveBytes(PeerSocketHandler.java:155)
at org.bitcoinj.net.ConnectionHandler.handleKey(ConnectionHandler.java:223)
at org.bitcoinj.net.NioClientManager.handleKey(NioClientManager.java:86)
at org.bitcoinj.net.NioClientManager.run(NioClientManager.java:122)
at com.google.common.util.concurrent.AbstractExecutionThreadService$1$2.run(AbstractExecutionThreadService.java:66)
at com.google.common.util.concurrent.Callables$4.run(Callables.java:122)
at org.bitcoinj.utils.ContextPropagatingThreadFactory$1.run(ContextPropagatingThreadFactory.java:49)
at java.base/java.lang.Thread.run(Thread.java:844)

Caused by: org.bitcoinj.core.ProtocolException: Claimed value length too large: 249
at org.bitcoinj.core.Message.readBytes(Message.java:331)
at org.bitcoinj.core.Message.readByteArray(Message.java:345)
at org.bitcoinj.core.AlertMessage.parse(AlertMessage.java:71)
at org.bitcoinj.core.Message.(Message.java:96)
at org.bitcoinj.core.Message.(Message.java:123)
at org.bitcoinj.core.AlertMessage.(AlertMessage.java:58)
at org.bitcoinj.core.BitcoinSerializer.makeAlertMessage(BitcoinSerializer.java:261)
at org.bitcoinj.core.BitcoinSerializer.makeMessage(BitcoinSerializer.java:219)
at org.bitcoinj.core.BitcoinSerializer.deserializePayload(BitcoinSerializer.java:183)
... 9 common frames omitted
Mar-18 13:29:16.705 [NioClientManager] INFO org.bitcoinj.core.PeerGroup: [139.59.151.88]:8333: Peer died (11 connected, 0 pending, 12 max)
Mar-18 13:29:16.705 [NioClientManager] WARN o.b.net.ConnectionHandler: Error handling SelectionKey: java.lang.IllegalStateException java.lang.IllegalStateException: null
at com.google.common.base.Preconditions.checkState(Preconditions.java:429)
at org.bitcoinj.net.ConnectionHandler.handleKey(ConnectionHandler.java:224)
at org.bitcoinj.net.NioClientManager.handleKey(NioClientManager.java:86)
at org.bitcoinj.net.NioClientManager.run(NioClientManager.java:122)
at com.google.common.util.concurrent.AbstractExecutionThreadService$1$2.run(AbstractExecutionThreadService.java:66)
at com.google.common.util.concurrent.Callables$4.run(Callables.java:122)
at org.bitcoinj.utils.ContextPropagatingThreadFactory$1.run(ContextPropagatingThreadFactory.java:49)
at java.base/java.lang.Thread.run(Thread.java:844)

@oscarguindzberg
Copy link
Contributor

oscarguindzberg commented Mar 18, 2019

I had a look.
It looks like the problem is a dishonest/buggy/old peer.

There is a peer sending an invalid "alert" msg.
Alert msgs were used in the past to alert problems on the btc protocol. Alert messages are deprecated but a peer is sending it anyway.

On top of that, the alert msg is malformed.
Bitcoin msg format is: header+payload.
Since the first couple of bytes of the payload printed on the log look like a header, I guess the malformed msg contains the msg header twice (unfortunately just the payload is printed on the log, not the full msg).

As part of bisq's bitcoinj 0.14.7 release I included some DoS protection
bisq-network/bitcoinj@66c5bd4 that just happened to detect this malformed msg.

I was able to reproduce the exception running bisq in dao-betanet (it is reproduced randomly).

I notice by default dao-betanet does not use the "safe" btc nodes provided by the bisq community. It uses either dns peer discovery or connects to the harcoded bitcoinj nodes.

I wrote a java main program that reproduces the problem:

import org.bitcoinj.core.BitcoinSerializer;
import org.bitcoinj.core.Message;
import org.bitcoinj.params.MainNetParams;

import java.io.IOException;
import java.nio.ByteBuffer;

import static org.bitcoinj.core.Utils.HEX;

public class Test {

    public static void main(String[] args) throws IOException {
        String msg = "f9beb4d9616c65727400000000000000a80000001bf9aaea60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50";
        String doubleHeaderMsg = "f9beb4d9616c65727400000000000000a80000001de0d306f9beb4d9616c65727400000000000000a80000001bf9aaea60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50";
        BitcoinSerializer serializer = new BitcoinSerializer(MainNetParams.get(), false);
        ByteBuffer bb = ByteBuffer.wrap(HEX.decode(doubleHeaderMsg));
        Message m = serializer.deserialize(bb);
        System.out.print(m);
    }
}

@oscarguindzberg
Copy link
Contributor

@ManfredKarrer by "PB" you mean protobuf? By "our branch" you mean https://github.com/bisq-network/bitcoinj/tree/bisq_0.14.7? I don't think this is a protobuf related problem.

@ManfredKarrer
Copy link
Member Author

Thanks for looking into it! Ah yes the dao-betanet uses public network and that is the reason we never saw that before as normal mainnet connect to our provided nodes which prob. do not relay such messages in the first place.
Will close as resolved then.

Yes with PB i meant protobuffer, just thought maybe we miss a new data field from recent releases....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants