From 52364c0e6782968bf1076a3330cb971d4bdea812 Mon Sep 17 00:00:00 2001 From: AntonAndell Date: Fri, 24 Mar 2023 10:18:42 +0100 Subject: [PATCH] Adapt client verification and update to fit java score --- .../main/java/ibc/ics02/client/IBCClient.java | 12 +- .../ibc/ics03/connection/IBCConnection.java | 10 +- .../ics04/channel/IBCChannelHandshake.java | 3 +- .../java/ibc/ics04/channel/IBCPacket.java | 12 +- .../java/ibc/ics02/client/ClientTest.java | 8 +- .../ibc/ics03/connection/ConnectionTest.java | 108 ++++-------------- .../ics04/channel/ChannelHandshakeTest.java | 82 ++++--------- .../java/ibc/ics04/channel/PacketTest.java | 68 +++++------ .../ibc/ics25/handler/IBCHandlerTestBase.java | 17 +-- .../ibc/icon/interfaces/ILightClient.java | 4 +- .../messages/ConsensusStateUpdate.java | 30 ----- .../messages/UpdateClientResponse.java | 32 +++--- .../main/java/ibc/mockclient/MockClient.java | 27 ++--- .../ibc/tendermint/TendermintLightClient.java | 36 +++--- 14 files changed, 140 insertions(+), 309 deletions(-) delete mode 100644 contracts/javascore/lib/src/main/java/ibc/icon/structs/messages/ConsensusStateUpdate.java diff --git a/contracts/javascore/ibc/src/main/java/ibc/ics02/client/IBCClient.java b/contracts/javascore/ibc/src/main/java/ibc/ics02/client/IBCClient.java index f1811e258..9e2cd3f05 100644 --- a/contracts/javascore/ibc/src/main/java/ibc/ics02/client/IBCClient.java +++ b/contracts/javascore/ibc/src/main/java/ibc/ics02/client/IBCClient.java @@ -37,16 +37,15 @@ public String _createClient(MsgCreateClient msg) { btpNetworkId.set(clientId, msg.getBtpNetworkId()); ILightClient client = getClient(clientId); UpdateClientResponse response = client.createClient(clientId, msg.getClientState(), msg.getConsensusState()); - Context.require(response.isOk()); byte[] clientKey = IBCCommitment.clientStateCommitmentKey(clientId); - Height updateHeight = Height.decode(response.getUpdate().getHeight()); + Height updateHeight = Height.decode(response.getHeight()); byte[] consensusKey = IBCCommitment.consensusStateCommitmentKey(clientId, updateHeight.getRevisionNumber(), updateHeight.getRevisionHeight()); sendBTPMessage(clientId, ByteUtil.join(clientKey, response.getClientStateCommitment())); - sendBTPMessage(clientId, ByteUtil.join(consensusKey, response.getUpdate().getConsensusStateCommitment())); + sendBTPMessage(clientId, ByteUtil.join(consensusKey, response.getConsensusStateCommitment())); return clientId; } @@ -56,19 +55,18 @@ public byte[] _updateClient(MsgUpdateClient msg) { ILightClient client = getClient(clientId); UpdateClientResponse response = client.updateClient(clientId, msg.getClientMessage()); - Context.require(response.isOk()); byte[] clientKey = IBCCommitment.clientStateCommitmentKey(clientId); - Height updateHeight = Height.decode(response.getUpdate().getHeight()); + Height updateHeight = Height.decode(response.getHeight()); byte[] consensusKey = IBCCommitment.consensusStateCommitmentKey(clientId, updateHeight.getRevisionNumber(), updateHeight.getRevisionHeight()); sendBTPMessage(clientId, ByteUtil.join(clientKey, response.getClientStateCommitment())); - sendBTPMessage(clientId, ByteUtil.join(consensusKey, response.getUpdate().getConsensusStateCommitment())); + sendBTPMessage(clientId, ByteUtil.join(consensusKey, response.getConsensusStateCommitment())); - return response.getUpdate().getHeight(); + return response.getHeight(); } private String generateClientIdentifier(String clientType) { diff --git a/contracts/javascore/ibc/src/main/java/ibc/ics03/connection/IBCConnection.java b/contracts/javascore/ibc/src/main/java/ibc/ics03/connection/IBCConnection.java index b20450e5c..4c22cc58e 100644 --- a/contracts/javascore/ibc/src/main/java/ibc/ics03/connection/IBCConnection.java +++ b/contracts/javascore/ibc/src/main/java/ibc/ics03/connection/IBCConnection.java @@ -192,7 +192,7 @@ public byte[] _connectionOpenConfirm(MsgConnectionOpenConfirm msg) { private void verifyClientState(ConnectionEnd connection, byte[] height, byte[] path, byte[] proof, byte[] clientStatebytes) { ILightClient client = getClient(connection.getClientId()); - boolean ok = client.verifyMembership( + client.verifyMembership( connection.getClientId(), height, BigInteger.ZERO, @@ -201,7 +201,6 @@ private void verifyClientState(ConnectionEnd connection, byte[] height, byte[] p connection.getCounterparty().getPrefix().getKeyPrefix(), path, clientStatebytes); - Context.require(ok, "failed to verify clientState"); } private void verifyClientConsensusState(ConnectionEnd connection, byte[] height, Height consensusHeight, @@ -211,7 +210,7 @@ private void verifyClientConsensusState(ConnectionEnd connection, byte[] height, consensusHeight.getRevisionHeight()); ILightClient client = getClient(connection.getClientId()); - boolean ok = client.verifyMembership( + client.verifyMembership( connection.getClientId(), height, BigInteger.ZERO, @@ -220,14 +219,12 @@ private void verifyClientConsensusState(ConnectionEnd connection, byte[] height, connection.getCounterparty().getPrefix().getKeyPrefix(), consensusPath, consensusStateBytes); - Context.require(ok, "failed to verify consensus state"); - } private void verifyConnectionState(ConnectionEnd connection, byte[] height, byte[] proof, String connectionId, ConnectionEnd counterpartyConnection) { ILightClient client = getClient(connection.getClientId()); - boolean ok = client.verifyMembership( + client.verifyMembership( connection.getClientId(), height, BigInteger.ZERO, @@ -236,7 +233,6 @@ private void verifyConnectionState(ConnectionEnd connection, byte[] height, byte connection.getCounterparty().getPrefix().getKeyPrefix(), IBCCommitment.connectionPath(connectionId), counterpartyConnection.encode()); - Context.require(ok, "failed to verify connection state"); } /* Internal functions */ diff --git a/contracts/javascore/ibc/src/main/java/ibc/ics04/channel/IBCChannelHandshake.java b/contracts/javascore/ibc/src/main/java/ibc/ics04/channel/IBCChannelHandshake.java index 1edece24a..57a9c9984 100644 --- a/contracts/javascore/ibc/src/main/java/ibc/ics04/channel/IBCChannelHandshake.java +++ b/contracts/javascore/ibc/src/main/java/ibc/ics04/channel/IBCChannelHandshake.java @@ -264,7 +264,7 @@ private void verifyChannelState( String channelId, Channel channel) { ILightClient client = getClient(connection.getClientId()); - boolean ok = client.verifyMembership( + client.verifyMembership( connection.getClientId(), height, BigInteger.ZERO, @@ -273,7 +273,6 @@ private void verifyChannelState( connection.getCounterparty().getPrefix().getKeyPrefix(), IBCCommitment.channelPath(portId, channelId), channel.encode()); - Context.require(ok, "failed to verify channel state"); } diff --git a/contracts/javascore/ibc/src/main/java/ibc/ics04/channel/IBCPacket.java b/contracts/javascore/ibc/src/main/java/ibc/ics04/channel/IBCPacket.java index ed3da769a..dc67a8534 100644 --- a/contracts/javascore/ibc/src/main/java/ibc/ics04/channel/IBCPacket.java +++ b/contracts/javascore/ibc/src/main/java/ibc/ics04/channel/IBCPacket.java @@ -324,7 +324,7 @@ private void verifyPacketCommitment( byte[] path, byte[] commitmentBytes) { ILightClient client = getClient(connection.getClientId()); - boolean ok = client.verifyMembership( + client.verifyMembership( connection.getClientId(), height, connection.getDelayPeriod(), @@ -333,7 +333,6 @@ private void verifyPacketCommitment( connection.getCounterparty().getPrefix().getKeyPrefix(), path, commitmentBytes); - Context.require(ok, "failed to verify packet commitment"); } private void verifyPacketAcknowledgement( @@ -343,7 +342,7 @@ private void verifyPacketAcknowledgement( byte[] path, byte[] acknowledgementCommitmentBytes) { ILightClient client = getClient(connection.getClientId()); - boolean ok = client.verifyMembership( + client.verifyMembership( connection.getClientId(), height, connection.getDelayPeriod(), @@ -352,7 +351,6 @@ private void verifyPacketAcknowledgement( connection.getCounterparty().getPrefix().getKeyPrefix(), path, acknowledgementCommitmentBytes); - Context.require(ok, "failed to verify packet acknowledgement commitment"); } private void verifyNextSequenceRecv( @@ -362,7 +360,7 @@ private void verifyNextSequenceRecv( byte[] path, byte[] commitmentBytes) { ILightClient client = getClient(connection.getClientId()); - boolean ok = client.verifyMembership( + client.verifyMembership( connection.getClientId(), height, connection.getDelayPeriod(), @@ -371,7 +369,6 @@ private void verifyNextSequenceRecv( connection.getCounterparty().getPrefix().getKeyPrefix(), path, commitmentBytes); - Context.require(ok, "failed to verify next sequence"); } private void verifyPacketReceiptAbsence( @@ -380,7 +377,7 @@ private void verifyPacketReceiptAbsence( byte[] proof, byte[] path) { ILightClient client = getClient(connection.getClientId()); - boolean ok = client.verifyNonMembership( + client.verifyNonMembership( connection.getClientId(), height, connection.getDelayPeriod(), @@ -388,7 +385,6 @@ private void verifyPacketReceiptAbsence( proof, connection.getCounterparty().getPrefix().getKeyPrefix(), path); - Context.require(ok, "failed to verify receipt absence"); } /* Internal functions */ diff --git a/contracts/javascore/ibc/src/test/java/ibc/ics02/client/ClientTest.java b/contracts/javascore/ibc/src/test/java/ibc/ics02/client/ClientTest.java index 8d53d5b11..49b4134e8 100644 --- a/contracts/javascore/ibc/src/test/java/ibc/ics02/client/ClientTest.java +++ b/contracts/javascore/ibc/src/test/java/ibc/ics02/client/ClientTest.java @@ -8,7 +8,6 @@ import ibc.icon.interfaces.ILightClientScoreInterface; import ibc.icon.score.util.ByteUtil; import ibc.icon.interfaces.ILightClient; -import ibc.icon.structs.messages.ConsensusStateUpdate; import ibc.icon.structs.messages.MsgCreateClient; import ibc.icon.structs.messages.MsgUpdateClient; import ibc.icon.structs.messages.UpdateClientResponse; @@ -97,8 +96,7 @@ void createClient() { Height consensusHeight = Height.newBuilder() .setRevisionHeight(1) .setRevisionNumber(2).build(); - ConsensusStateUpdate update = new ConsensusStateUpdate(consensusStateCommitment, consensusHeight.toByteArray()); - UpdateClientResponse response = new UpdateClientResponse(clientStateCommitment, update, true); + UpdateClientResponse response = new UpdateClientResponse(clientStateCommitment, consensusStateCommitment, consensusHeight.toByteArray()); when(lightClient.mock.createClient(msg.getClientType() + "-" + BigInteger.ZERO, msg.getClientState(), msg.getConsensusState())).thenReturn(response); @@ -148,9 +146,7 @@ public void updateClient() { .setRevisionHeight(1) .setRevisionNumber(2).build(); - ConsensusStateUpdate update = new ConsensusStateUpdate(consensusStateCommitment, consensusHeight.toByteArray()); - - UpdateClientResponse response = new UpdateClientResponse(clientStateCommitment, update, true); + UpdateClientResponse response = new UpdateClientResponse(clientStateCommitment, consensusStateCommitment, consensusHeight.toByteArray()); when(lightClient.mock.updateClient(msg.getClientId(), msg.getClientMessage())).thenReturn(response); diff --git a/contracts/javascore/ibc/src/test/java/ibc/ics03/connection/ConnectionTest.java b/contracts/javascore/ibc/src/test/java/ibc/ics03/connection/ConnectionTest.java index 7c58819e6..98e12ff8b 100644 --- a/contracts/javascore/ibc/src/test/java/ibc/ics03/connection/ConnectionTest.java +++ b/contracts/javascore/ibc/src/test/java/ibc/ics03/connection/ConnectionTest.java @@ -182,65 +182,6 @@ void connectionOpenTry_failedConnectionStateVerification() { assertTrue(e.getMessage().contains(expectedErrorMessage)); } - @Test - void connectionOpenTry_invalidStates() { - // Arrange - MsgConnectionOpenTry msg = new MsgConnectionOpenTry(); - msg.setClientId(clientId); - msg.setCounterparty(counterparty.toByteArray()); - msg.setDelayPeriod(delayPeriod); - msg.setClientStateBytes(new byte[1]); - msg.setCounterpartyVersions(new byte[][] { version.toByteArray() }); - msg.setProofInit(new byte[2]); - msg.setProofClient(new byte[3]); - msg.setProofConsensus(new byte[4]); - msg.setProofHeight(proofHeight.toByteArray()); - msg.setConsensusHeight(consensusHeight.toByteArray()); - - Counterparty expectedCounterparty = Counterparty.newBuilder() - .setClientId(msg.getClientId()) - .setConnectionId("") - .setPrefix(prefix).build(); - - ConnectionEnd counterpartyConnection = ConnectionEnd.newBuilder() - .setClientId(counterparty.getClientId()) - .addVersions(0, version) - .setState(ConnectionEnd.State.STATE_INIT) - .setDelayPeriod(msg.getDelayPeriod().longValue()) - .setCounterparty(expectedCounterparty).build(); - - // verifyConnectionState - byte[] connectionPath = IBCCommitment.connectionPath(msg.getCounterparty().getConnectionId()); - when(lightClient.mock.verifyMembership(msg.getClientId(), - msg.getProofHeightRaw(), BigInteger.ZERO, - BigInteger.ZERO, msg.getProofInit(), prefix.getKeyPrefix().toByteArray(), connectionPath, - counterpartyConnection.toByteArray())) - .thenReturn(false).thenReturn(true); - - // verifyClientState - byte[] clientStatePath = IBCCommitment.clientStatePath(msg.getCounterparty().getClientId()); - when(lightClient.mock.verifyMembership(msg.getClientId(), msg.getProofHeightRaw(), BigInteger.ZERO, - BigInteger.ZERO, msg.getProofClient(), prefix.getKeyPrefix().toByteArray(), clientStatePath, - msg.getClientStateBytes())) - .thenReturn(false); - - // Act & Assert - String expectedErrorMessage = "failed to verify connection state"; - Executable clientVerificationFailed = () -> connection.invoke(owner, - "_connectionOpenTry", msg); - AssertionError e = assertThrows(AssertionError.class, - clientVerificationFailed); - assertTrue(e.getMessage().contains(expectedErrorMessage)); - - expectedErrorMessage = "failed to verify clientState"; - Executable stateVerificationFailed = () -> connection.invoke(owner, - "_connectionOpenTry", msg); - e = assertThrows(AssertionError.class, - stateVerificationFailed); - assertTrue(e.getMessage().contains(expectedErrorMessage)); - - } - @Test void connectionOpenTry() { // Arrange @@ -270,28 +211,26 @@ void connectionOpenTry() { String expectedConnectionId = "connection-0"; + // Act + connection.invoke(owner, "_connectionOpenTry", msg); + + // Assert // verifyConnectionState byte[] connectionPath = IBCCommitment.connectionPath(msg.getCounterparty().getConnectionId()); - when(lightClient.mock.verifyMembership(msg.getClientId(), + verify(lightClient.mock).verifyMembership(msg.getClientId(), msg.getProofHeightRaw(), BigInteger.ZERO, BigInteger.ZERO, msg.getProofInit(), prefix.getKeyPrefix().toByteArray(), connectionPath, - counterpartyConnection.toByteArray())).thenReturn(true); + counterpartyConnection.toByteArray()); // verifyClientState byte[] clientStatePath = IBCCommitment.clientStatePath(msg.getCounterparty().getClientId()); - when(lightClient.mock.verifyMembership(msg.getClientId(), msg.getProofHeightRaw(), BigInteger.ZERO, + verify(lightClient.mock).verifyMembership(msg.getClientId(), msg.getProofHeightRaw(), BigInteger.ZERO, BigInteger.ZERO, msg.getProofClient(), prefix.getKeyPrefix().toByteArray(), clientStatePath, - msg.getClientStateBytes())) - .thenReturn(true); - - // Act - connection.invoke(owner, "_connectionOpenTry", msg); + msg.getClientStateBytes()); - // Assert ConnectionEnd expectedConnection = ConnectionEnd.newBuilder(baseConnection) .setState(ConnectionEnd.State.STATE_TRYOPEN).build(); - byte[] connectionKey = IBCCommitment.connectionCommitmentKey(expectedConnectionId); verify(connectionSpy) .sendBTPMessage( @@ -365,23 +304,21 @@ void connectionOpenAck() { .setDelayPeriod(delayPeriod.longValue()) .setCounterparty(expectedCounterparty).build(); + // Act + connection.invoke(owner, "_connectionOpenAck", msg); + + // Assert // verifyConnectionState byte[] connectionPath = IBCCommitment.connectionPath(msg.getCounterpartyConnectionID()); - when(lightClient.mock.verifyMembership(clientId, msg.getProofHeightRaw(), BigInteger.ZERO, BigInteger.ZERO, + verify(lightClient.mock).verifyMembership(clientId, msg.getProofHeightRaw(), BigInteger.ZERO, BigInteger.ZERO, msg.getProofTry(), prefix.getKeyPrefix().toByteArray(), connectionPath, - counterpartyConnection.toByteArray())) - .thenReturn(true); + counterpartyConnection.toByteArray()); // verifyClientState byte[] clientStatePath = IBCCommitment.clientStatePath(counterparty.getClientId()); - when(lightClient.mock.verifyMembership(clientId, msg.getProofHeightRaw(), BigInteger.ZERO, BigInteger.ZERO, - msg.getProofClient(), prefix.getKeyPrefix().toByteArray(), clientStatePath, msg.getClientStateBytes())) - .thenReturn(true); - - // Act - connection.invoke(owner, "_connectionOpenAck", msg); + verify(lightClient.mock).verifyMembership(clientId, msg.getProofHeightRaw(), BigInteger.ZERO, BigInteger.ZERO, + msg.getProofClient(), prefix.getKeyPrefix().toByteArray(), clientStatePath, msg.getClientStateBytes()); - // Assert Counterparty counterparty = Counterparty.newBuilder(baseConnection.getCounterparty()) .setConnectionId(msg.getCounterpartyConnectionID()).build(); ConnectionEnd expectedConnection = ConnectionEnd.newBuilder(baseConnection) @@ -438,17 +375,16 @@ void connectionOpenConfirm() { .setDelayPeriod(delayPeriod.longValue()) .setCounterparty(expectedCounterparty).build(); - // verifyConnectionState - byte[] connectionPath = IBCCommitment.connectionPath(counterparty.getConnectionId()); - when(lightClient.mock.verifyMembership(clientId, msg.getProofHeightRaw(), BigInteger.ZERO, BigInteger.ZERO, - msg.getProofAck(), prefix.getKeyPrefix().toByteArray(), connectionPath, - counterpartyConnection.toByteArray())) - .thenReturn(true); - // Act connection.invoke(owner, "_connectionOpenConfirm", msg); // Assert + // verifyConnectionState + byte[] connectionPath = IBCCommitment.connectionPath(counterparty.getConnectionId()); + verify(lightClient.mock).verifyMembership(clientId, msg.getProofHeightRaw(), BigInteger.ZERO, BigInteger.ZERO, + msg.getProofAck(), prefix.getKeyPrefix().toByteArray(), connectionPath, + counterpartyConnection.toByteArray()); + ConnectionEnd expectedConnection = ConnectionEnd.newBuilder(baseConnection) .setState(ConnectionEnd.State.STATE_OPEN).build(); diff --git a/contracts/javascore/ibc/src/test/java/ibc/ics04/channel/ChannelHandshakeTest.java b/contracts/javascore/ibc/src/test/java/ibc/ics04/channel/ChannelHandshakeTest.java index a79819430..297c3ecb3 100644 --- a/contracts/javascore/ibc/src/test/java/ibc/ics04/channel/ChannelHandshakeTest.java +++ b/contracts/javascore/ibc/src/test/java/ibc/ics04/channel/ChannelHandshakeTest.java @@ -292,45 +292,6 @@ void channelOpenTry_wrongState() { assertTrue(e.getMessage().contains(expectedErrorMessage)); } - @Test - void channelOpenTry_failedVerification() { - // Arrange - addConnection(connectionId, baseConnection); - baseChannel = Channel.newBuilder(baseChannel) - .setState(Channel.State.STATE_TRYOPEN).build(); - - MsgChannelOpenTry msg = new MsgChannelOpenTry(); - msg.setPortId(portId); - msg.setChannel(baseChannel.toByteArray()); - msg.setCounterpartyVersion(channelVersion); - msg.setProofHeight(proofHeight.toByteArray()); - msg.setProofInit(new byte[1]); - - Counterparty expectedCounterparty = Counterparty.newBuilder() - .setPortId(msg.getPortId()) - .setChannelId("").build(); - - Channel expectedChannel = Channel.newBuilder() - .setState(Channel.State.STATE_INIT) - .setOrderingValue(msg.getChannel().getOrdering()) - .setCounterparty(expectedCounterparty) - .addAllConnectionHops(List.of(baseConnection.getCounterparty().getConnectionId())) - .setVersion(msg.getCounterpartyVersion()).build(); - - when(lightClient.mock.verifyMembership(clientId, msg.getProofHeightRaw(), - BigInteger.ZERO, BigInteger.ZERO, - msg.getProofInit(), prefix.getKeyPrefix().toByteArray(), IBCCommitment.channelPath(portId, - channelId), - expectedChannel.toByteArray())).thenReturn(false); - - // Act & Assert - String expectedErrorMessage = "failed to verify channel state"; - Executable wrongState = () -> channel.invoke(owner, "_channelOpenTry", msg); - AssertionError e = assertThrows(AssertionError.class, - wrongState); - assertTrue(e.getMessage().contains(expectedErrorMessage)); - } - @Test void channelOpenTry() { // Arrange @@ -356,17 +317,16 @@ void channelOpenTry() { .addAllConnectionHops(List.of(baseConnection.getCounterparty().getConnectionId())) .setVersion(msg.getCounterpartyVersion()).build(); - when(lightClient.mock.verifyMembership(clientId, msg.getProofHeightRaw(), - BigInteger.ZERO, BigInteger.ZERO, - msg.getProofInit(), prefix.getKeyPrefix().toByteArray(), - IBCCommitment.channelPath(portId, channelId), expectedChannel.toByteArray())) - .thenReturn(true); // Act channel.invoke(owner, "_channelOpenTry", msg); // Assert - byte[] key = IBCCommitment.channelCommitmentKey(portId, channelId); + verify(lightClient.mock).verifyMembership(clientId, msg.getProofHeightRaw(), + BigInteger.ZERO, BigInteger.ZERO, + msg.getProofInit(), prefix.getKeyPrefix().toByteArray(), + IBCCommitment.channelPath(portId, channelId), expectedChannel.toByteArray()); + byte[] key = IBCCommitment.channelCommitmentKey(portId, channelId); verify(channelSpy).sendBTPMessage(clientId, ByteUtil.join(key, IBCCommitment.keccak256(baseChannel.toByteArray()))); @@ -402,15 +362,14 @@ void channelOpenAck() { .addAllConnectionHops(List.of(baseConnection.getCounterparty().getConnectionId())) .setVersion(msg.getCounterpartyVersion()).build(); - when(lightClient.mock.verifyMembership(clientId, msg.getProofHeightRaw(), - BigInteger.ZERO, BigInteger.ZERO, - msg.getProofTry(), prefix.getKeyPrefix().toByteArray(), IBCCommitment.channelPath(portId, - channelId), - counterpartyChannel.toByteArray())).thenReturn(true); - channel.invoke(owner, "_channelOpenAck", msg); // Assert + verify(lightClient.mock).verifyMembership(clientId, msg.getProofHeightRaw(), + BigInteger.ZERO, BigInteger.ZERO, + msg.getProofTry(), prefix.getKeyPrefix().toByteArray(), + IBCCommitment.channelPath(portId, channelId),counterpartyChannel.toByteArray()); + Counterparty counterparty = Counterparty.newBuilder(baseChannel.getCounterparty()) .setChannelId(msg.getCounterpartyChannelId()).build(); Channel expectedChannel = Channel.newBuilder(baseChannel) @@ -446,15 +405,14 @@ void channelOpenConfirm() { .addAllConnectionHops(List.of(baseConnection.getCounterparty().getConnectionId())) .setVersion(baseChannel.getVersion()).build(); - when(lightClient.mock.verifyMembership(clientId, msg.getProofHeightRaw(), - BigInteger.ZERO, BigInteger.ZERO, - msg.getProofAck(), prefix.getKeyPrefix().toByteArray(), IBCCommitment.channelPath(portId, channelId), - counterpartyChannel.toByteArray())).thenReturn(true); - // Act channel.invoke(owner, "_channelOpenConfirm", msg); // Assert + verify(lightClient.mock).verifyMembership(clientId, msg.getProofHeightRaw(), + BigInteger.ZERO, BigInteger.ZERO, + msg.getProofAck(), prefix.getKeyPrefix().toByteArray(), IBCCommitment.channelPath(portId, channelId), + counterpartyChannel.toByteArray()); Channel expectedChannel = Channel.newBuilder(baseChannel) .setState(Channel.State.STATE_OPEN).build(); @@ -506,16 +464,16 @@ void channelCloseConfirm() { .addAllConnectionHops(List.of(baseConnection.getCounterparty().getConnectionId())) .setVersion(baseChannel.getVersion()).build(); - when(lightClient.mock.verifyMembership(clientId, msg.getProofHeightRaw(), - BigInteger.ZERO, BigInteger.ZERO, - msg.getProofInit(), prefix.getKeyPrefix().toByteArray(), IBCCommitment.channelPath(portId, - channelId), - counterpartyChannel.toByteArray())).thenReturn(true); - // Act channel.invoke(owner, "_channelCloseConfirm", msg); // Assert + verify(lightClient.mock).verifyMembership(clientId, msg.getProofHeightRaw(), + BigInteger.ZERO, BigInteger.ZERO, + msg.getProofInit(), prefix.getKeyPrefix().toByteArray(), IBCCommitment.channelPath(portId, + channelId), + counterpartyChannel.toByteArray()); + Channel expectedChannel = Channel.newBuilder(baseChannel) .setState(Channel.State.STATE_CLOSED).build(); diff --git a/contracts/javascore/ibc/src/test/java/ibc/ics04/channel/PacketTest.java b/contracts/javascore/ibc/src/test/java/ibc/ics04/channel/PacketTest.java index a9ade2cd3..db7fa2c5d 100644 --- a/contracts/javascore/ibc/src/test/java/ibc/ics04/channel/PacketTest.java +++ b/contracts/javascore/ibc/src/test/java/ibc/ics04/channel/PacketTest.java @@ -356,7 +356,8 @@ void recvPacket_lowTimeoutTimestamp() { // Act & Assert String expectedErrorMessage = "block timestamp >= packet timeout timestamp"; - Executable lowTimeoutTimestamp = () -> packet.invoke(owner, "_recvPacket", basePacket, new byte[0], new byte[0]); + Executable lowTimeoutTimestamp = () -> packet.invoke(owner, "_recvPacket", basePacket, new byte[0], + new byte[0]); AssertionError e = assertThrows(AssertionError.class, lowTimeoutTimestamp); assertTrue(e.getMessage().contains(expectedErrorMessage)); @@ -373,10 +374,6 @@ void recvPacket_doubleReceive_UnOrdered() { basePacket.getSourceChannel(), basePacket.getSequence()); byte[] commitmentBytes = createPacketCommitment(basePacket); - when(lightClient.mock.verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), - BigInteger.ZERO, - proof, prefix.getKeyPrefix(), commitmentPath, commitmentBytes)).thenReturn(true); - packet.invoke(owner, "_recvPacket", basePacket, proof, proofHeight.encode()); // Act & Assert @@ -400,18 +397,18 @@ void recvPacket_outOfOrder_UnOrdered() { basePacket.getSourceChannel(), basePacket.getSequence().add(BigInteger.ONE)); byte[] commitmentBytes = createPacketCommitment(basePacket); - when(lightClient.mock.verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), - BigInteger.ZERO, - proof, prefix.getKeyPrefix(), commitmentPath1, commitmentBytes)).thenReturn(true); - when(lightClient.mock.verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), - BigInteger.ZERO, - proof, prefix.getKeyPrefix(), commitmentPath2, commitmentBytes)).thenReturn(true); // Act basePacket.setSequence(BigInteger.TWO); packet.invoke(owner, "_recvPacket", basePacket, proof, proofHeight.encode()); + // Assert basePacket.setSequence(BigInteger.ONE); packet.invoke(owner, "_recvPacket", basePacket, proof, proofHeight.encode()); + + verify(lightClient.mock).verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), + BigInteger.ZERO, proof, prefix.getKeyPrefix(), commitmentPath1, commitmentBytes); + verify(lightClient.mock).verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), + BigInteger.ZERO, proof, prefix.getKeyPrefix(), commitmentPath2, commitmentBytes); } @Test @@ -422,13 +419,6 @@ void recvPacket_futureReceive_Ordered() { basePacket.setSequence(BigInteger.TWO); byte[] proof = new byte[1]; - byte[] commitmentPath = IBCCommitment.packetCommitmentPath(basePacket.getSourcePort(), - basePacket.getSourceChannel(), basePacket.getSequence()); - byte[] commitmentBytes = createPacketCommitment(basePacket); - - when(lightClient.mock.verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), - BigInteger.ZERO, proof, prefix.getKeyPrefix(), commitmentPath, commitmentBytes)).thenReturn(true); - // Act & Assert String expectedErrorMessage = "packet sequence != next receive sequence"; Executable notNext = () -> packet.invoke(owner, "_recvPacket", basePacket, proof, proofHeight.encode()); @@ -448,14 +438,13 @@ void recvPacket_UnOrdered() { basePacket.getSourceChannel(), basePacket.getSequence()); byte[] commitmentBytes = createPacketCommitment(basePacket); - when(lightClient.mock.verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), - BigInteger.ZERO, - proof, prefix.getKeyPrefix(), commitmentPath, commitmentBytes)).thenReturn(true); // Act packet.invoke(owner, "_recvPacket", basePacket, proof, proofHeight.encode()); // Assert assertTrue((boolean) packet.call("getPacketReceipt", portId, channelId, basePacket.getSequence())); + verify(lightClient.mock).verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), + BigInteger.ZERO, proof, prefix.getKeyPrefix(), commitmentPath, commitmentBytes); } @Test @@ -469,15 +458,15 @@ void recvPacket_Ordered() { basePacket.getSourceChannel(), basePacket.getSequence()); byte[] commitmentBytes = createPacketCommitment(basePacket); - when(lightClient.mock.verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), - BigInteger.ZERO, - proof, prefix.getKeyPrefix(), commitmentPath, commitmentBytes)).thenReturn(true); // Act packet.invoke(owner, "_recvPacket", basePacket, proof, proofHeight.encode()); // Assert assertEquals(basePacket.getSequence().add(BigInteger.ONE), packet.call("getNextSequenceReceive", portId, channelId)); + verify(lightClient.mock).verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), + BigInteger.ZERO, + proof, prefix.getKeyPrefix(), commitmentPath, commitmentBytes); } @Test @@ -512,17 +501,17 @@ void acknowledgePacket() { byte[] acknowledgement = new byte[4]; byte[] proof = new byte[5]; + // Act + packet.invoke(owner, "_acknowledgePacket", basePacket, acknowledgement, proof, proofHeight.encode()); + + // Assert byte[] commitmentPath = IBCCommitment.packetAcknowledgementCommitmentPath(basePacket.getDestinationPort(), basePacket.getDestinationChannel(), basePacket.getSequence()); - when(lightClient.mock.verifyMembership(clientId, proofHeight.encode(), + verify(lightClient.mock).verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), BigInteger.ZERO, proof, prefix.getKeyPrefix(), commitmentPath, - IBCCommitment.sha256(acknowledgement))).thenReturn(true); - - // Act - packet.invoke(owner, "_acknowledgePacket", basePacket, acknowledgement, proof, proofHeight.encode()); + IBCCommitment.sha256(acknowledgement)); - // Assert byte[] packetCommitmentKey = IBCCommitment.packetCommitmentKey(basePacket.getSourcePort(), basePacket.getSourceChannel(), basePacket.getSequence()); Object storedCommitment = packet.call("getCommitment", packetCommitmentKey); @@ -589,16 +578,16 @@ void timeoutPacket_unOrdered() { when(lightClient.mock.getTimestampAtHeight(clientId, latestHeight.encode())).thenReturn(BigInteger.ZERO); packet.invoke(owner, "_sendPacket", basePacket); + // Act + packet.invoke(owner, "_timeoutPacket", basePacket, proofHeight.encode(), proof, BigInteger.ZERO); + // Assert byte[] commitmentPath = IBCCommitment.packetReceiptCommitmentPath(basePacket.getDestinationPort(), basePacket.getDestinationChannel(), basePacket.getSequence()); - when(lightClient.mock.verifyNonMembership(clientId, proofHeight.encode(), + verify(lightClient.mock).verifyNonMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), BigInteger.ZERO, - proof, prefix.getKeyPrefix(), commitmentPath)).thenReturn(true); - // Act - packet.invoke(owner, "_timeoutPacket", basePacket, proofHeight.encode(), proof, BigInteger.ZERO); + proof, prefix.getKeyPrefix(), commitmentPath); - // Assert byte[] packetCommitmentKey = IBCCommitment.packetCommitmentKey(basePacket.getSourcePort(), basePacket.getSourceChannel(), basePacket.getSequence()); Object storedCommitment = packet.call("getCommitment", packetCommitmentKey); @@ -624,16 +613,15 @@ void timeoutPacket_Ordered() { when(lightClient.mock.getTimestampAtHeight(clientId, latestHeight.encode())).thenReturn(BigInteger.ZERO); packet.invoke(owner, "_sendPacket", basePacket, basePacket.getSequence()); + packet.invoke(owner, "_timeoutPacket", basePacket, proofHeight.encode(), proof, basePacket.getSequence()); + // Assert byte[] commitmentPath = IBCCommitment.nextSequenceRecvCommitmentPath(basePacket.getDestinationPort(), basePacket.getDestinationChannel()); - when(lightClient.mock.verifyMembership(clientId, proofHeight.encode(), + verify(lightClient.mock).verifyMembership(clientId, proofHeight.encode(), baseConnection.getDelayPeriod(), BigInteger.ZERO, - proof, prefix.getKeyPrefix(), commitmentPath, basePacket.getSequence().toByteArray())).thenReturn(true); - // Act - packet.invoke(owner, "_timeoutPacket", basePacket, proofHeight.encode(), proof, basePacket.getSequence()); + proof, prefix.getKeyPrefix(), commitmentPath, basePacket.getSequence().toByteArray()); - // Assert byte[] packetCommitmentKey = IBCCommitment.packetCommitmentKey(basePacket.getSourcePort(), basePacket.getSourceChannel(), basePacket.getSequence()); Object storedCommitment = packet.call("getCommitment", packetCommitmentKey); diff --git a/contracts/javascore/ibc/src/test/java/ibc/ics25/handler/IBCHandlerTestBase.java b/contracts/javascore/ibc/src/test/java/ibc/ics25/handler/IBCHandlerTestBase.java index 06038a7df..043a02ff7 100644 --- a/contracts/javascore/ibc/src/test/java/ibc/ics25/handler/IBCHandlerTestBase.java +++ b/contracts/javascore/ibc/src/test/java/ibc/ics25/handler/IBCHandlerTestBase.java @@ -80,14 +80,6 @@ protected void setup() throws Exception { lightClient = new MockContract<>(ILightClientScoreInterface.class, ILightClient.class, sm, owner); module = new MockContract<>(IIBCModuleScoreInterface.class, IIBCModule.class, sm, owner); - when(lightClient.mock.verifyMembership(any(String.class), any(byte[].class), any(BigInteger.class), - any(BigInteger.class), - any(byte[].class), any(byte[].class), any(byte[].class), any(byte[].class))).thenReturn(true); - - when(lightClient.mock.verifyNonMembership(any(String.class), any(byte[].class), any(BigInteger.class), - any(BigInteger.class), - any(byte[].class), any(byte[].class), any(byte[].class))).thenReturn(true); - when(lightClient.mock.getClientState(any(String.class))).thenReturn(new byte[0]); prefix = MerklePrefix.newBuilder() @@ -109,9 +101,10 @@ void createClient() { msg.setClientType(clientType); msg.setBtpNetworkId(4); - ConsensusStateUpdate update = new ConsensusStateUpdate(new byte[0], + UpdateClientResponse response = new UpdateClientResponse( + new byte[0], + new byte[0], Height.getDefaultInstance().toByteArray()); - UpdateClientResponse response = new UpdateClientResponse(new byte[0], update, true); when(lightClient.mock.createClient(any(String.class), any(byte[].class), any(byte[].class))) .thenReturn(response); @@ -136,9 +129,7 @@ void updateClient() { .setRevisionHeight(1) .setRevisionNumber(2).build(); - ConsensusStateUpdate update = new ConsensusStateUpdate(consensusStateCommitment, consensusHeight.toByteArray()); - - UpdateClientResponse response = new UpdateClientResponse(clientStateCommitment, update, true); + UpdateClientResponse response = new UpdateClientResponse(clientStateCommitment, consensusStateCommitment, consensusHeight.toByteArray()); when(lightClient.mock.updateClient(msg.getClientId(), msg.getClientMessage())).thenReturn(response); diff --git a/contracts/javascore/lib/src/main/java/ibc/icon/interfaces/ILightClient.java b/contracts/javascore/lib/src/main/java/ibc/icon/interfaces/ILightClient.java index a6e85e3f1..437864352 100644 --- a/contracts/javascore/lib/src/main/java/ibc/icon/interfaces/ILightClient.java +++ b/contracts/javascore/lib/src/main/java/ibc/icon/interfaces/ILightClient.java @@ -46,7 +46,7 @@ public interface ILightClient { * a given CommitmentPath at the specified height. The caller is expected to construct the full CommitmentPath * from a CommitmentPrefix and a standardized path (as defined in ICS 24). */ - Boolean verifyMembership( + void verifyMembership( String clientId, byte[] heightBytes, BigInteger delayTimePeriod, @@ -61,7 +61,7 @@ Boolean verifyMembership( * CommitmentPath at a specified height. The caller is expected to construct the full CommitmentPath from a * CommitmentPrefix and a standardized path (as defined in ICS 24). */ - Boolean verifyNonMembership( + void verifyNonMembership( String clientId, byte[] heightBytes, BigInteger delayTimePeriod, diff --git a/contracts/javascore/lib/src/main/java/ibc/icon/structs/messages/ConsensusStateUpdate.java b/contracts/javascore/lib/src/main/java/ibc/icon/structs/messages/ConsensusStateUpdate.java deleted file mode 100644 index 6f7952d02..000000000 --- a/contracts/javascore/lib/src/main/java/ibc/icon/structs/messages/ConsensusStateUpdate.java +++ /dev/null @@ -1,30 +0,0 @@ -package ibc.icon.structs.messages; - -public class ConsensusStateUpdate { - public ConsensusStateUpdate(byte[] consensusStateCommitment, byte[] height) { - this.consensusStateCommitment = consensusStateCommitment; - this.height = height; - } - - // commitment for updated consensusState - private byte[] consensusStateCommitment; - // updated height - private byte[] height; - - public byte[] getConsensusStateCommitment() { - return consensusStateCommitment; - } - - public void setConsensusStateCommitment(byte[] consensusStateCommitment) { - this.consensusStateCommitment = consensusStateCommitment; - } - - public byte[] getHeight() { - return height; - } - - public void setHeight(byte[] height) { - this.height = height; - } - -} diff --git a/contracts/javascore/lib/src/main/java/ibc/icon/structs/messages/UpdateClientResponse.java b/contracts/javascore/lib/src/main/java/ibc/icon/structs/messages/UpdateClientResponse.java index 8abfeecac..cc7d31d3d 100644 --- a/contracts/javascore/lib/src/main/java/ibc/icon/structs/messages/UpdateClientResponse.java +++ b/contracts/javascore/lib/src/main/java/ibc/icon/structs/messages/UpdateClientResponse.java @@ -1,14 +1,19 @@ package ibc.icon.structs.messages; public class UpdateClientResponse { + // current client state private byte[] clientStateCommitment; - private ConsensusStateUpdate update; - private boolean ok; + // commitment for updated consensusState + private byte[] consensusStateCommitment; + // updated height + private byte[] height; - public UpdateClientResponse(byte[] clientStateCommitment, ConsensusStateUpdate update, boolean ok) { + + + public UpdateClientResponse(byte[] clientStateCommitment, byte[] consensusStateCommitment, byte[] height) { this.clientStateCommitment = clientStateCommitment; - this.update = update; - this.ok = ok; + this.consensusStateCommitment = consensusStateCommitment; + this.height = height; } public byte[] getClientStateCommitment() { @@ -19,20 +24,19 @@ public void setClientStateCommitment(byte[] clientStateCommitment) { this.clientStateCommitment = clientStateCommitment; } - public ConsensusStateUpdate getUpdate() { - return update; + public byte[] getConsensusStateCommitment() { + return consensusStateCommitment; } - public void setUpdate(ConsensusStateUpdate update) { - this.update = update; + public void setConsensusStateCommitment(byte[] consensusStateCommitment) { + this.consensusStateCommitment = consensusStateCommitment; } - public boolean isOk() { - return ok; + public byte[] getHeight() { + return height; } - public void setOk(boolean ok) { - this.ok = ok; + public void setHeight(byte[] height) { + this.height = height; } - } diff --git a/contracts/javascore/lightclients/mockclient/src/main/java/ibc/mockclient/MockClient.java b/contracts/javascore/lightclients/mockclient/src/main/java/ibc/mockclient/MockClient.java index 7aa6eb362..33ee1f5d9 100644 --- a/contracts/javascore/lightclients/mockclient/src/main/java/ibc/mockclient/MockClient.java +++ b/contracts/javascore/lightclients/mockclient/src/main/java/ibc/mockclient/MockClient.java @@ -3,7 +3,6 @@ import java.math.BigInteger; import score.Context; import score.annotation.External; -import ibc.icon.structs.messages.ConsensusStateUpdate; import ibc.icon.structs.messages.UpdateClientResponse; import icon.proto.core.client.Height; @@ -42,26 +41,28 @@ public byte[] getClientState(String clientId) { @External public UpdateClientResponse createClient(String clientId, byte[] clientStateBytes, byte[] consensusStateBytes) { - ConsensusStateUpdate update = new ConsensusStateUpdate(IBCCommitment.keccak256(consensusStateBytes), - new Height().encode()); - UpdateClientResponse response = new UpdateClientResponse(IBCCommitment.keccak256(clientStateBytes), update, - true); + UpdateClientResponse response = new UpdateClientResponse( + IBCCommitment.keccak256(clientStateBytes), + IBCCommitment.keccak256(consensusStateBytes), + new Height().encode() + ); return response; } @External(readonly = true) public UpdateClientResponse updateClient(String clientId, byte[] clientMessageBytes) { - ConsensusStateUpdate update = new ConsensusStateUpdate(IBCCommitment.keccak256(new byte[1]), - new Height().encode()); - UpdateClientResponse response = new UpdateClientResponse(IBCCommitment.keccak256(clientMessageBytes), update, - true); + UpdateClientResponse response = new UpdateClientResponse( + IBCCommitment.keccak256(clientMessageBytes), + IBCCommitment.keccak256(clientMessageBytes), + new Height().encode() + ); return response; } @External - public boolean verifyMembership( + public void verifyMembership( String clientId, byte[] heightBytes, BigInteger delayTimePeriod, @@ -70,12 +71,10 @@ public boolean verifyMembership( byte[] prefix, byte[] path, byte[] value) { - - return true; } @External - public boolean verifyNonMembership( + public void verifyNonMembership( String clientId, byte[] heightBytes, BigInteger delayTimePeriod, @@ -83,7 +82,5 @@ public boolean verifyNonMembership( byte[] proof, byte[] prefix, byte[] path) { - - return true; } } diff --git a/contracts/javascore/lightclients/tendermint/src/main/java/ibc/tendermint/TendermintLightClient.java b/contracts/javascore/lightclients/tendermint/src/main/java/ibc/tendermint/TendermintLightClient.java index 490d60f68..edb36b772 100644 --- a/contracts/javascore/lightclients/tendermint/src/main/java/ibc/tendermint/TendermintLightClient.java +++ b/contracts/javascore/lightclients/tendermint/src/main/java/ibc/tendermint/TendermintLightClient.java @@ -9,7 +9,6 @@ import score.DictDB; import score.annotation.External; import ibc.icon.score.util.NullChecker; -import ibc.icon.structs.messages.ConsensusStateUpdate; import ibc.icon.structs.messages.UpdateClientResponse; import icon.proto.core.client.Height; @@ -97,10 +96,11 @@ public UpdateClientResponse createClient(String clientId, byte[] clientStateByte clientStates.set(clientId, clientStateBytes); consensusStates.at(clientId).set(clientState.getLatestHeight(), consensusStateBytes); - ConsensusStateUpdate update = new ConsensusStateUpdate(IBCCommitment.keccak256(consensusStateBytes), - newHeight(clientState.getLatestHeight()).encode()); - UpdateClientResponse response = new UpdateClientResponse(IBCCommitment.keccak256(clientStateBytes), update, - true); + UpdateClientResponse response = new UpdateClientResponse( + IBCCommitment.keccak256(clientStateBytes), + IBCCommitment.keccak256(consensusStateBytes), + newHeight(clientState.getLatestHeight()).encode() + ); return response; } @@ -156,11 +156,11 @@ public UpdateClientResponse updateClient(String clientId, byte[] clientMessageBy processedTimes.at(clientId).set(tmHeader.getSignedHeader().getHeader().getHeight(), BigInteger.valueOf(Context.getBlockTimestamp())); - ConsensusStateUpdate consensusStateUpdate = new ConsensusStateUpdate( + UpdateClientResponse response = new UpdateClientResponse( + IBCCommitment.keccak256(encodedClientState), IBCCommitment.keccak256(encodedConsensusState), - newHeight(tmHeader.getSignedHeader().getHeader().getHeight()).encode()); - UpdateClientResponse response = new UpdateClientResponse(IBCCommitment.keccak256(encodedClientState), - consensusStateUpdate, true); + newHeight(tmHeader.getSignedHeader().getHeader().getHeight()).encode() + ); return response; } @@ -180,16 +180,18 @@ public UpdateClientResponse updateClient(String clientId, byte[] clientMessageBy BigInteger.valueOf(Context.getBlockHeight())); processedTimes.at(clientId).set(tmHeader.getSignedHeader().getHeader().getHeight(), BigInteger.valueOf(Context.getBlockTimestamp())); - ConsensusStateUpdate consensusStateUpdate = new ConsensusStateUpdate( - IBCCommitment.keccak256(encodedConsensusState), newHeight(clientState.getLatestHeight()).encode()); - UpdateClientResponse response = new UpdateClientResponse(IBCCommitment.keccak256(encodedClientState), - consensusStateUpdate, true); + + UpdateClientResponse response = new UpdateClientResponse( + IBCCommitment.keccak256(encodedClientState), + IBCCommitment.keccak256(encodedConsensusState), + newHeight(clientState.getLatestHeight()).encode() + ); return response; } @External - public boolean verifyMembership( + public void verifyMembership( String clientId, byte[] heightBytes, BigInteger delayTimePeriod, @@ -208,12 +210,12 @@ public boolean verifyMembership( byte[] root = consensusState.getRoot().getHash(); - return true; + Context.require(true, "Verification failed"); } @External - public boolean verifyNonMembership( + public void verifyNonMembership( String clientId, byte[] heightBytes, BigInteger delayTimePeriod, @@ -231,7 +233,7 @@ public boolean verifyNonMembership( byte[] root = consensusState.getRoot().getHash(); - return true; + Context.require(true, "Verification failed"); } // checkValidity checks if the Tendermint header is valid.