Skip to content

Commit

Permalink
fix: change messageHash back to only message
Browse files Browse the repository at this point in the history
  • Loading branch information
aureliusbtc committed Jun 4, 2022
1 parent bb89d48 commit 7199ae1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
4 changes: 1 addition & 3 deletions packages/contracts/contracts/Home.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {
uint256 indexed leafIndex,
uint64 indexed destinationAndNonce,
bytes32 committedRoot,
uint32 optimisticSeconds,
bytes message
);

Expand Down Expand Up @@ -189,7 +188,7 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {
_messageBody
);
// insert the hashed message into the Merkle tree
bytes32 _messageHash = keccak256(abi.encodePacked(_message, _optimisticSeconds));
bytes32 _messageHash = keccak256(_message);
tree.insert(_messageHash);
// enqueue the new Merkle root after inserting the message
queue.enqueue(root());
Expand All @@ -200,7 +199,6 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {
count() - 1,
_destinationAndNonce(_destinationDomain, _nonce),
committedRoot,
_optimisticSeconds,
_message
);
}
Expand Down
10 changes: 4 additions & 6 deletions packages/contracts/contracts/ReplicaManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,10 @@ contract ReplicaManager is Version0, Initializable, OwnableUpgradeable {
function proveAndProcess(
uint32 _remoteDomain,
bytes memory _message,
uint32 _optimisticSeconds,
bytes32[32] calldata _proof,
uint256 _index
) external {
require(prove(_remoteDomain, _message, _optimisticSeconds, _proof, _index), "!prove");
require(prove(_remoteDomain, _message, _proof, _index), "!prove");
process(_message);
}

Expand Down Expand Up @@ -404,26 +403,25 @@ contract ReplicaManager is Version0, Initializable, OwnableUpgradeable {
* @dev For convenience, we allow proving against any previous root.
* This means that witnesses never need to be updated for the new root
* @param _message Formatted message
* @param _optimisticSeconds Latency period requested by app on Home, included in part of Merkle proof
* @param _proof Merkle proof of inclusion for leaf
* @param _index Index of leaf in home's merkle tree
* @return Returns true if proof was valid and `prove` call succeeded
**/
function prove(
uint32 _remoteDomain,
bytes memory _message,
uint32 _optimisticSeconds,
bytes32[32] calldata _proof,
uint256 _index
) public returns (bool) {
bytes32 _leaf = keccak256(abi.encodePacked(_message, _optimisticSeconds));
uint32 optimisticSeconds = _message.ref(0).optimisticSeconds();
bytes32 _leaf = keccak256(_message);
ReplicaLib.Replica storage replica = allReplicas[activeReplicas[_remoteDomain]];
// ensure that message has not been proven or processed
require(replica.messages[_leaf] == ReplicaLib.MessageStatus.None, "!MessageStatus.None");
// calculate the expected root based on the proof
bytes32 _calculatedRoot = MerkleLib.branchRoot(_leaf, _proof, _index);
// if the root is valid, change status to Proven
if (acceptableRoot(_remoteDomain, _optimisticSeconds, _calculatedRoot)) {
if (acceptableRoot(_remoteDomain, optimisticSeconds, _calculatedRoot)) {
replica.setMessageStatus(_leaf, ReplicaLib.MessageStatus.Processed);
return true;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts/test/Home.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ contract HomeTest is SynapseTestWithUpdaterManager {
uint256 indexed leafIndex,
uint64 indexed destinationAndNonce,
bytes32 committedRoot,
uint32 optimisticSeconds,
bytes message
);

Expand All @@ -104,14 +103,13 @@ contract HomeTest is SynapseTestWithUpdaterManager {
optimisticSeconds,
messageBody
);
bytes32 messageHash = keccak256(abi.encodePacked(message, optimisticSeconds));
bytes32 messageHash = keccak256(message);
vm.expectEmit(true, true, true, true);
emit Dispatch(
messageHash,
home.count(),
(uint64(remoteDomain) << 32) | nonce,
home.committedRoot(),
optimisticSeconds,
message
);
vm.prank(sender);
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/test/ReplicaManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ contract ReplicaManagerTest is SynapseTest {
// Relayer relays a new root signed by updater on Home chain
function test_successfulUpdate() public {
bytes memory newMessage = "new root";
bytes32 newRoot = keccak256(abi.encodePacked(newMessage, optimisticSeconds));
bytes32 newRoot = keccak256(newMessage);
assertEq(replicaManager.updater(), vm.addr(updaterPK));
bytes memory sig = signRemoteUpdate(updaterPK, committedRoot, newRoot);
// Root doesn't exist yet
Expand All @@ -144,15 +144,15 @@ contract ReplicaManagerTest is SynapseTest {

function test_updateWithIncorrectSig() public {
bytes memory newMessage = "new root";
bytes32 newRoot = keccak256(abi.encodePacked(newMessage, optimisticSeconds));
bytes32 newRoot = keccak256(newMessage);
bytes memory sig = signRemoteUpdate(fakeUpdaterPK, committedRoot, newRoot);
vm.expectRevert("!updater sig");
replicaManager.update(remoteDomain, committedRoot, newRoot, sig);
}

function test_acceptableRoot() public {
bytes memory newMessage = "new root";
bytes32 newRoot = keccak256(abi.encodePacked(newMessage, optimisticSeconds));
bytes32 newRoot = keccak256(newMessage);
test_successfulUpdate();
vm.warp(block.timestamp + optimisticSeconds + 1);
assertTrue(replicaManager.acceptableRoot(remoteDomain, optimisticSeconds, newRoot));
Expand Down

0 comments on commit 7199ae1

Please sign in to comment.