Skip to content

Commit

Permalink
Merge pull request #16 from icon-project/bgkwon-update-bmv
Browse files Browse the repository at this point in the history
Fix Bug BMV
  • Loading branch information
kwon528 authored Sep 25, 2023
2 parents 091f88a + 237aba8 commit c5d6f1b
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 263 deletions.
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

0 comments on commit c5d6f1b

Please sign in to comment.