Test rust-produced domain hashes

pull/334/head
Trevor Porter 3 years ago
parent 554fca9ee6
commit a9b64260c8
  1. 10
      solidity/core/contracts/validator-manager/MultisigValidatorManager.sol
  2. 16
      solidity/core/test/validator-manager/multisigValidatorManager.test.ts

@ -65,7 +65,7 @@ abstract contract MultisigValidatorManager is Ownable {
) Ownable() { ) Ownable() {
// Set immutables. // Set immutables.
outboxDomain = _outboxDomain; outboxDomain = _outboxDomain;
outboxDomainHash = keccak256(abi.encodePacked(_outboxDomain, "ABACUS")); outboxDomainHash = domainHash(_outboxDomain);
// Enroll validators. Reverts if there are any duplicates. // Enroll validators. Reverts if there are any duplicates.
uint256 _validatorSetLength = _validatorSet.length; uint256 _validatorSetLength = _validatorSet.length;
@ -166,6 +166,14 @@ abstract contract MultisigValidatorManager is Ownable {
return _validatorSignatureCount >= quorumThreshold; return _validatorSignatureCount >= quorumThreshold;
} }
/**
* @notice Hash of domain concatenated with "ABACUS".
* @param _domain The domain to hash.
*/
function domainHash(uint32 _domain) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_domain, "ABACUS"));
}
// ============ Internal Functions ============ // ============ Internal Functions ============
/** /**

@ -15,6 +15,8 @@ const OUTBOX_DOMAIN_HASH = ethers.utils.keccak256(
); );
const QUORUM_THRESHOLD = 1; const QUORUM_THRESHOLD = 1;
const domainHashTestCases = require('../../../vectors/domainHash.json');
describe('MultisigValidatorManager', async () => { describe('MultisigValidatorManager', async () => {
let validatorManager: TestMultisigValidatorManager, let validatorManager: TestMultisigValidatorManager,
signer: SignerWithAddress, signer: SignerWithAddress,
@ -232,4 +234,18 @@ describe('MultisigValidatorManager', async () => {
).to.be.revertedWith('!sorted signers'); ).to.be.revertedWith('!sorted signers');
}); });
}); });
describe('#domainHash', () => {
it('matches Rust-produced domain hashes', async () => {
// Compare Rust output in json file to solidity output (json file matches
// hash for local domain of 1000)
for (let testCase of domainHashTestCases) {
const { expectedDomainHash } = testCase;
const domainHash = await validatorManager.domainHash(
testCase.outboxDomain,
);
expect(domainHash).to.equal(expectedDomainHash);
}
});
});
}); });

Loading…
Cancel
Save