From 7baae7de1f875bfddf6c3b56ac1709b45beadc65 Mon Sep 17 00:00:00 2001 From: -f Date: Fri, 20 Dec 2024 14:29:06 +0530 Subject: [PATCH] rm merkleTree --- solidity/contracts/libs/FraudMessage.sol | 15 +++---- .../contracts/middleware/FraudProofRouter.sol | 14 ++----- solidity/test/FraudProofRouter.t.sol | 42 +++---------------- 3 files changed, 16 insertions(+), 55 deletions(-) diff --git a/solidity/contracts/libs/FraudMessage.sol b/solidity/contracts/libs/FraudMessage.sol index 89c457167b..41426f8163 100644 --- a/solidity/contracts/libs/FraudMessage.sol +++ b/solidity/contracts/libs/FraudMessage.sol @@ -29,14 +29,12 @@ struct Attribution { library FraudMessage { function encode( address signer, - bytes32 merkleTree, bytes32 digest, Attribution memory attribution ) internal pure returns (bytes memory) { return abi.encodePacked( signer, - merkleTree, digest, uint8(attribution.fraudType), attribution.timestamp @@ -45,15 +43,14 @@ library FraudMessage { function decode( bytes calldata _message - ) internal pure returns (address, bytes32, bytes32, Attribution memory) { - require(_message.length == 91, "Invalid message length"); + ) internal pure returns (address, bytes32, Attribution memory) { + require(_message.length == 59, "Invalid message length"); address signer = address(bytes20(_message[0:20])); - bytes32 merkleTree = bytes32(_message[20:52]); - bytes32 digest = bytes32(_message[52:84]); - FraudType fraudType = FraudType(uint8(_message[84])); - uint48 timestamp = uint48(bytes6(_message[85:91])); + bytes32 digest = bytes32(_message[20:52]); + FraudType fraudType = FraudType(uint8(_message[52])); + uint48 timestamp = uint48(bytes6(_message[53:59])); - return (signer, merkleTree, digest, Attribution(fraudType, timestamp)); + return (signer, digest, Attribution(fraudType, timestamp)); } } diff --git a/solidity/contracts/middleware/FraudProofRouter.sol b/solidity/contracts/middleware/FraudProofRouter.sol index 313f58d65a..8387d4e500 100644 --- a/solidity/contracts/middleware/FraudProofRouter.sol +++ b/solidity/contracts/middleware/FraudProofRouter.sol @@ -24,8 +24,8 @@ contract FraudProofRouter is GasRouter { // The AttributeCheckpointFraud contract to obtain the attributions from AttributeCheckpointFraud public immutable attributeCheckpointFraud; - // Mapping to store the fraud attributions for a given origin, signer, merkle tree, and digest for easy access for client contracts to aide slashing - mapping(uint32 origin => mapping(address signer => mapping(bytes32 merkleTree => mapping(bytes32 digest => Attribution)))) + // Mapping to store the fraud attributions for a given origin, signer, and digest for easy access for client contracts to aide slashing + mapping(uint32 origin => mapping(address signer => mapping(bytes32 digest => Attribution))) public fraudAttributions; // ===================== Events ======================= @@ -74,13 +74,11 @@ contract FraudProofRouter is GasRouter { * @notice Sends a fraud proof attribution. * @param _signer The address of the signer attributed with fraud. * @param _digest The digest associated with the fraud. - * @param _merkleTree The merkle tree associated with the fraud. * @return The message ID of the sent fraud proof. */ function sendFraudProof( uint32 _destination, address _signer, - bytes32 _merkleTree, bytes32 _digest ) external returns (bytes32) { Attribution memory attribution = attributeCheckpointFraud.attributions( @@ -91,9 +89,7 @@ contract FraudProofRouter is GasRouter { require(attribution.timestamp != 0, "Attribution does not exist"); if (_destination == mailbox.localDomain()) { - fraudAttributions[_destination][_signer][_merkleTree][ - _digest - ] = attribution; + fraudAttributions[_destination][_signer][_digest] = attribution; emit LocalFraudProofReceived(_signer, _digest, attribution); @@ -101,7 +97,6 @@ contract FraudProofRouter is GasRouter { } else { bytes memory encodedMessage = FraudMessage.encode( _signer, - _merkleTree, _digest, attribution ); @@ -132,12 +127,11 @@ contract FraudProofRouter is GasRouter { ) internal override { ( address signer, - bytes32 merkleTree, bytes32 digest, Attribution memory attribution ) = FraudMessage.decode(_message); - fraudAttributions[_origin][signer][merkleTree][digest] = attribution; + fraudAttributions[_origin][signer][digest] = attribution; emit FraudProofReceived(_origin, signer, digest, attribution); } diff --git a/solidity/test/FraudProofRouter.t.sol b/solidity/test/FraudProofRouter.t.sol index 672ac974ef..3535043837 100644 --- a/solidity/test/FraudProofRouter.t.sol +++ b/solidity/test/FraudProofRouter.t.sol @@ -8,7 +8,6 @@ import {TypeCasts} from "../contracts/libs/TypeCasts.sol"; import {TestAttributeCheckpointFraud} from "../contracts/test/TestAttributeCheckpointFraud.sol"; import {FraudProofRouter} from "../contracts/middleware/FraudProofRouter.sol"; import {MockMailbox} from "../contracts/mock/MockMailbox.sol"; -import {TestMerkle} from "../contracts/test/TestMerkle.sol"; contract FraudProofRouterTest is Test { using TypeCasts for address; @@ -17,7 +16,6 @@ contract FraudProofRouterTest is Test { uint32 public constant DESTINATION_DOMAIN = 2; MockMailbox internal localMailbox; MockMailbox internal remoteMailbox; - TestMerkle internal testMerkleHook; TestAttributeCheckpointFraud public testAcf; FraudProofRouter public originFpr; FraudProofRouter public remoteFpr; @@ -32,8 +30,6 @@ contract FraudProofRouterTest is Test { localMailbox.addRemoteMailbox(DESTINATION_DOMAIN, remoteMailbox); remoteMailbox.addRemoteMailbox(LOCAL_DOMAIN, localMailbox); - testMerkleHook = new TestMerkle(); - testAcf = new TestAttributeCheckpointFraud(); vm.startPrank(OWNER); @@ -66,7 +62,6 @@ contract FraudProofRouterTest is Test { function test_sendFraudProof( address _signer, bytes32 _digest, - bytes32 _merkleTree, uint8 _fraudType, uint48 _timestamp ) public { @@ -84,12 +79,7 @@ contract FraudProofRouterTest is Test { Attribution(fraudTypeEnum, uint48(block.timestamp)) ); - originFpr.sendFraudProof( - DESTINATION_DOMAIN, - _signer, - _merkleTree, - _digest - ); + originFpr.sendFraudProof(DESTINATION_DOMAIN, _signer, _digest); vm.expectEmit(true, true, true, true, address(remoteFpr)); emit FraudProofRouter.FraudProofReceived( @@ -101,7 +91,7 @@ contract FraudProofRouterTest is Test { remoteMailbox.processNextInboundMessage(); (FraudType actualFraudType, uint48 actualTimestamp) = remoteFpr - .fraudAttributions(LOCAL_DOMAIN, _signer, _merkleTree, _digest); + .fraudAttributions(LOCAL_DOMAIN, _signer, _digest); assert(actualFraudType == fraudTypeEnum); assertEq(actualTimestamp, block.timestamp); @@ -109,12 +99,7 @@ contract FraudProofRouterTest is Test { function test_sendFraudProof_noAttribution() public { vm.expectRevert("Attribution does not exist"); - originFpr.sendFraudProof( - DESTINATION_DOMAIN, - SIGNER, - TypeCasts.addressToBytes32(address(testMerkleHook)), - DIGEST - ); + originFpr.sendFraudProof(DESTINATION_DOMAIN, SIGNER, DIGEST); } function test_sendFraudProof_routerNotEnrolled() public { @@ -122,31 +107,16 @@ contract FraudProofRouterTest is Test { testAcf.mockSetAttribution(SIGNER, DIGEST, fraudType); vm.expectRevert("No router enrolled for domain: 3"); - originFpr.sendFraudProof( - 3, - SIGNER, - TypeCasts.addressToBytes32(address(testMerkleHook)), - DIGEST - ); + originFpr.sendFraudProof(3, SIGNER, DIGEST); } function test_sendFraudProof_localDomain() public { testAcf.mockSetAttribution(SIGNER, DIGEST, FraudType.Whitelist); - originFpr.sendFraudProof( - LOCAL_DOMAIN, - SIGNER, - TypeCasts.addressToBytes32(address(testMerkleHook)), - DIGEST - ); + originFpr.sendFraudProof(LOCAL_DOMAIN, SIGNER, DIGEST); (FraudType actualFraudType, uint48 actualTimestamp) = originFpr - .fraudAttributions( - LOCAL_DOMAIN, - SIGNER, - TypeCasts.addressToBytes32(address(testMerkleHook)), - DIGEST - ); + .fraudAttributions(LOCAL_DOMAIN, SIGNER, DIGEST); assert(actualFraudType == FraudType.Whitelist); assertEq(actualTimestamp, block.timestamp);