From f6fc6531e776acb25cfcdb3cfd4f6f3a3b401af8 Mon Sep 17 00:00:00 2001 From: sendra Date: Tue, 9 Jan 2024 16:04:34 +0100 Subject: [PATCH] fix: removed conditional for after confirmation case --- src/contracts/CrossChainReceiver.sol | 16 +++------------- src/contracts/interfaces/ICrossChainReceiver.sol | 16 ---------------- tests/CrossChainReceiver.t.sol | 9 +++++---- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/contracts/CrossChainReceiver.sol b/src/contracts/CrossChainReceiver.sol index 94bba715..52f99fb9 100644 --- a/src/contracts/CrossChainReceiver.sol +++ b/src/contracts/CrossChainReceiver.sol @@ -162,18 +162,6 @@ contract CrossChainReceiver is OwnableWithGuardian, ICrossChainReceiver { bytes32 transactionId = TransactionUtils.getId(encodedTransaction); - // if envelope was confirmed before, just return - if (_envelopesState[envelopeId] != EnvelopeState.None) { - emit TransactionReceivedWhenConfirmed( - transactionId, - envelopeId, - originChainId, - transaction, - msg.sender - ); - return; - } - TransactionState storage internalTransaction = _transactionsState[transactionId]; ReceiverConfiguration memory configuration = _configurationsByChain[originChainId] .configuration; @@ -209,9 +197,11 @@ contract CrossChainReceiver is OwnableWithGuardian, ICrossChainReceiver { // from additional bridges after reaching required number of confirmations // >= is used for the case when confirmations gets lowered before message reached the old _requiredConfirmations // but on receiving new messages it surpasses the current _requiredConfirmations. So it doesn't get stuck (if using ==) + // Envelope can only be set as confirmed or delivered once if ( configuration.requiredConfirmation > 0 && - newConfirmations >= configuration.requiredConfirmation + newConfirmations >= configuration.requiredConfirmation && + _envelopesState[envelopeId] == EnvelopeState.None ) { _envelopesState[envelopeId] = EnvelopeState.Delivered; try diff --git a/src/contracts/interfaces/ICrossChainReceiver.sol b/src/contracts/interfaces/ICrossChainReceiver.sol index bcf597e7..71d75a33 100644 --- a/src/contracts/interfaces/ICrossChainReceiver.sol +++ b/src/contracts/interfaces/ICrossChainReceiver.sol @@ -92,22 +92,6 @@ interface ICrossChainReceiver { Delivered } - /** - * @notice emitted when a transaction has been received after a message has already been confirmed - * @param transactionId id of the transaction - * @param envelopeId id of the envelope - * @param originChainId id of the chain where the envelope originated - * @param transaction the Transaction type data - * @param bridgeAdapter address of the bridge adapter who received the message (deployed on current network) - */ - event TransactionReceivedWhenConfirmed( - bytes32 transactionId, - bytes32 indexed envelopeId, - uint256 indexed originChainId, - Transaction transaction, - address indexed bridgeAdapter - ); - /** * @notice emitted when a transaction has been received successfully * @param transactionId id of the transaction diff --git a/tests/CrossChainReceiver.t.sol b/tests/CrossChainReceiver.t.sol index 08636dbe..e59dad98 100644 --- a/tests/CrossChainReceiver.t.sol +++ b/tests/CrossChainReceiver.t.sol @@ -506,12 +506,13 @@ contract CrossChainReceiverTest is BaseTest { // receive 2nd cross chain message after its already confirmed hoax(BRIDGE_ADAPTER_2); vm.expectEmit(true, true, true, true); - emit TransactionReceivedWhenConfirmed( + emit TransactionReceived( txExtended.transactionId, txExtended.envelopeId, txExtended.envelope.originChainId, txExtended.transaction, - BRIDGE_ADAPTER_2 + BRIDGE_ADAPTER_2, + 2 ); crossChainReceiver.receiveCrossChainMessage( txExtended.transactionEncoded, @@ -521,12 +522,12 @@ contract CrossChainReceiverTest is BaseTest { // check internal transaction assertEq( crossChainReceiver.isTransactionReceivedByAdapter(txExtended.transactionId, BRIDGE_ADAPTER_2), - false + true ); internalTransactionState = crossChainReceiver.getTransactionState(txExtended.transactionId); internalEnvelopeState = crossChainReceiver.getEnvelopeState(txExtended.envelopeId); - assertEq(internalTransactionState.confirmations, 1); + assertEq(internalTransactionState.confirmations, 2); assertEq(internalTransactionState.firstBridgedAt, block.timestamp); assertTrue(internalEnvelopeState == ICrossChainReceiver.EnvelopeState.Delivered); }