Skip to content

Commit

Permalink
For #12857
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Feb 23, 2023
1 parent 129be5a commit 44a9e22
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 160 deletions.
6 changes: 3 additions & 3 deletions core/packages/contracts/contracts/BasicInboundChannel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.9;

import "./ParachainClient.sol";
import "./utils/MerkleProof.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

contract BasicInboundChannel {
uint256 public constant MAX_GAS_PER_MESSAGE = 100000;
Expand All @@ -27,10 +27,10 @@ contract BasicInboundChannel {
function submit(
Message calldata message,
bytes32[] calldata leafProof,
bool[] calldata hashSides,
bytes calldata parachainHeaderProof
) external {
bytes32 commitment = MerkleProof.processProof(message, leafProof, hashSides);
bytes32 leafHash = keccak256(abi.encode(message));
bytes32 commitment = MerkleProof.processProof(leafProof, leafHash);
require(
parachainClient.verifyCommitment(commitment, parachainHeaderProof),
"Invalid proof"
Expand Down
17 changes: 4 additions & 13 deletions core/packages/contracts/contracts/BeefyClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ pragma solidity ^0.8.9;

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "./utils/Bitfield.sol";
import "./utils/MMRProof.sol";
import "./ScaleCodec.sol";
import "./utils/MerkleProof.sol";

/**
* @title BeefyClient
Expand Down Expand Up @@ -210,7 +210,7 @@ contract BeefyClient is Ownable {
ValidatorProof calldata proof
) internal {
// Check if merkle proof is valid based on the validatorSetRoot
if (!isValidatorInSet(vset, proof.account, proof.index, proof.proof)) {
if (!isValidatorInSet(vset, proof.account, proof.proof)) {
revert InvalidValidatorProof();
}

Expand Down Expand Up @@ -463,7 +463,7 @@ contract BeefyClient is Ownable {
revert InvalidValidatorProof();
}

if (!isValidatorInSet(vset, proof.account, proof.index, proof.proof)) {
if (!isValidatorInSet(vset, proof.account, proof.proof)) {
revert InvalidValidatorProof();
}

Expand Down Expand Up @@ -507,25 +507,16 @@ contract BeefyClient is Ownable {
/**
* @dev Checks if a validators address is a member of the merkle tree
* @param addr The address of the validator to check
* @param index The index of the validator to check, starting at 0
* @param proof Merkle proof required for validation of the address
* @return true if the validator is in the set
*/
function isValidatorInSet(
ValidatorSet memory vset,
address addr,
uint256 index,
bytes32[] calldata proof
) internal pure returns (bool) {
bytes32 hashedLeaf = keccak256(abi.encodePacked(addr));
return
MerkleProof.verifyMerkleLeafAtPosition(
vset.root,
hashedLeaf,
index,
vset.length,
proof
);
return MerkleProof.verify(proof, vset.root, hashedLeaf);
}

/**
Expand Down
9 changes: 3 additions & 6 deletions core/packages/contracts/contracts/ParachainClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.9;

import "./BeefyClient.sol";
import "./utils/MerkleProof.sol";
import "./ScaleCodec.sol";

contract ParachainClient {
Expand Down Expand Up @@ -54,11 +53,9 @@ contract ParachainClient {
);

// Compute the merkle root hash of all parachain heads
bytes32 parachainHeadsRoot = MerkleProof.computeRootFromProofAtPosition(
parachainHeadHash,
proof.headProof.pos,
proof.headProof.width,
proof.headProof.proof
bytes32 parachainHeadsRoot = MerkleProof.processProof(
proof.headProof.proof,
parachainHeadHash
);

bytes32 leafHash = createMMRLeaf(proof.leafPartial, parachainHeadsRoot);
Expand Down
101 changes: 0 additions & 101 deletions core/packages/contracts/contracts/utils/MerkleProof.sol

This file was deleted.

Loading

0 comments on commit 44a9e22

Please sign in to comment.