Skip to content

Commit d57c19a

Browse files
Compute Commitment Hash (#1709)
* compute commitment hash * test
1 parent 2716aee commit d57c19a

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

contracts/src/BeefyClient.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,14 @@ contract BeefyClient {
465465
return Bitfield.createBitfield(bitsToSet, length);
466466
}
467467

468+
/**
469+
* @dev Compute the hash of a commitment
470+
* @param commitment the commitment to hash
471+
*/
472+
function computeCommitmentHash(Commitment calldata commitment) external pure returns (bytes32) {
473+
return keccak256(encodeCommitment(commitment));
474+
}
475+
468476
/**
469477
* @dev Helper to create a final bitfield, with subsampled validator selections
470478
* @param commitmentHash contains the commitmentHash signed by the validators

contracts/test/BeefyClient.t.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,4 +879,11 @@ contract BeefyClientTest is Test {
879879
commitment, bitfield, fiatShamirValidatorProofs, mmrLeaf, mmrLeafProofs, leafProofOrder
880880
);
881881
}
882+
883+
function testComputeCommitmentHash() public {
884+
BeefyClient.Commitment memory commitment = initialize(setId);
885+
bytes32 computedHash = beefyClient.computeCommitmentHash(commitment);
886+
// commitHash is loaded from the test data file and should match
887+
assertEq(computedHash, commitHash);
888+
}
882889
}

0 commit comments

Comments
 (0)