From 2858b366b308c257b2b1713a728278e8aef526ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Wed, 27 Sep 2023 12:49:09 +0200 Subject: [PATCH] add new contract read API --- contracts/src/L1/L1ScrollMessenger.sol | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/contracts/src/L1/L1ScrollMessenger.sol b/contracts/src/L1/L1ScrollMessenger.sol index 1824e6bc1..79e59d719 100644 --- a/contracts/src/L1/L1ScrollMessenger.sol +++ b/contracts/src/L1/L1ScrollMessenger.sol @@ -104,6 +104,31 @@ contract L1ScrollMessenger is ScrollMessengerBase, IL1ScrollMessenger { emit UpdateMaxReplayTimes(0, 3); } + /************************* + * Public View Functions * + *************************/ + + function isProofValid( + address _from, + address _to, + uint256 _value, + uint256 _nonce, + bytes memory _message, + L2MessageProof memory _proof + ) external view { + bytes32 _xDomainCalldataHash = keccak256(_encodeXDomainCalldata(_from, _to, _value, _nonce, _message)); + require(!isL2MessageExecuted[_xDomainCalldataHash], "Message was already successfully executed"); + + address _rollup = rollup; + require(IScrollChain(_rollup).isBatchFinalized(_proof.batchIndex), "Batch is not finalized"); + bytes32 _messageRoot = IScrollChain(_rollup).withdrawRoots(_proof.batchIndex); + + require( + WithdrawTrieVerifier.verifyMerkleProof(_messageRoot, _xDomainCalldataHash, _nonce, _proof.merkleProof), + "Invalid proof" + ); + } + /***************************** * Public Mutating Functions * *****************************/