Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bug BMV #16

Merged
merged 6 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bmv/contracts/BtpMessageVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ contract BtpMessageVerifier is IBMV {
string memory _srcNetworkId,
uint256 _networkTypeId,
bytes memory _firstBlockHeader,
uint256 _sequenceOffset
uint256 _sequenceOffset,
uint256 _nextMessageOffset
) {
bmc = _bmc;
srcNetworkId = _srcNetworkId;
Expand All @@ -68,7 +69,7 @@ contract BtpMessageVerifier is IBMV {
header.mainHeight,
header.messageCount,
header.messageSn,
header.messageSn,
header.messageSn + _nextMessageOffset,
header.nextValidators
);
}
Expand Down
209 changes: 0 additions & 209 deletions bmv/contracts/BtpMessageVerifierV2.sol

This file was deleted.

40 changes: 26 additions & 14 deletions bmv/contracts/libraries/BlockUpdateLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,24 @@ library BlockUpdateLib {
RLPDecode.RLPItem memory i = enc.toRlpItem();
RLPDecode.RLPItem[] memory l = i.toList();

return
Header(
l[0].toUint(),
l[1].toUint(),
bytes32(l[2].toBytes()),
l[3].payloadLen() > 0 ? decodeNSRootPath(l[3].toRlpBytes()) : new Path[](0),
l[4].toUint(),
l[5].toUint() >> 1,
l[5].toUint() & 1 == 1,
l[6].payloadLen() > 0 ? bytes32(l[6].toBytes()) : bytes32(0),
l[7].toUint(),
l[8].payloadLen() > 0 ? bytes32(l[8].toBytes()) : bytes32(0),
l[5].toUint() & 1 == 1 ? decodeValidators(l[9].toBytes()) : new address[](0)
);
header = Header(
l[0].toUint(),
l[1].toUint(),
bytes32(l[2].toBytes()),
l[3].payloadLen() > 0 ? decodeNSRootPath(l[3].toRlpBytes()) : new Path[](0),
l[4].toUint(),
l[5].toUint() >> 1,
l[5].toUint() & 1 == 1,
l[6].payloadLen() > 0 ? bytes32(l[6].toBytes()) : bytes32(0),
l[7].toUint(),
l[8].payloadLen() > 0 ? bytes32(l[8].toBytes()) : bytes32(0),
l[9].payloadLen() > 0 ? decodeValidators(l[9].toBytes()) : new address[](0)
);

if (header.nextValidators.length > 0) {
require(header.nextProofContextHash == calcProofContextHash(header.nextValidators),
"Inconsistent next proof context hashes");
}
}

function decodeProof(bytes memory enc) internal pure returns (Proof memory) {
Expand Down Expand Up @@ -127,4 +131,12 @@ library BlockUpdateLib {
}
return validators;
}

function calcProofContextHash(address[] memory validators) private pure returns (bytes32) {
bytes[] memory buf = new bytes[](validators.length);
for (uint256 i = 0; i < validators.length; i++) {
buf[i] = RLPEncode.encodeAddress(validators[i]);
}
return keccak256(RLPEncode.encodeList(RLPEncode.encodeList(buf)));
}
}
3 changes: 2 additions & 1 deletion bmv/migrations/2_deploy_bmv.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = async function (deployer, network, accounts) {
SRC_NETWORK_ID,
NETWORK_TYPE_ID,
FIRST_BLOCK_UPDATE,
SEQUENCE_OFFSET
SEQUENCE_OFFSET,
0
);
};
Loading