Skip to content

Commit

Permalink
Calling leaf-node leaf instead of node
Browse files Browse the repository at this point in the history
  • Loading branch information
Phanco committed Dec 7, 2023
1 parent 0946af7 commit 8e41149
Show file tree
Hide file tree
Showing 5 changed files with 875 additions and 876 deletions.
8 changes: 4 additions & 4 deletions script/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ contract Utils is Script {

// Limitation of parseJSON, only bytes32 is supported
// to convert b32Address back to bytes20, shift 96 bits to the left
// i.e. bytes20(node.b32Address << 96)
/// @notice This struct is store merkleTree node.
struct MerkleTreeNode {
// i.e. bytes20(leaf.b32Address << 96)
/// @notice This struct is store merkleTree leaf.
struct MerkleTreeLeaf {
bytes32 b32Address;
uint64 balanceBeddows;
bytes32[] mandatoryKeys;
Expand All @@ -38,8 +38,8 @@ contract Utils is Script {

/// @notice This struct is used to read MerkleTree from JSON file.
struct MerkleTree {
MerkleTreeLeaf[] leaf;
bytes32 merkleRoot;
MerkleTreeNode[] node;
}

/// @notice This function reads L1 addresses from JSON file.
Expand Down
20 changes: 10 additions & 10 deletions src/L2/L2Claim.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ contract L2Claim {
bytes20 _lskAddress,
uint64 _amount,
bytes32[] calldata _proof,
bytes32 _node,
bytes32 _leaf,
address _recipient
)
internal
{
require(!claimed[_lskAddress], "Already Claimed");
require(MerkleProof.verify(_proof, merkleRoot, _node), "Invalid Proof");
require(MerkleProof.verify(_proof, merkleRoot, _leaf), "Invalid Proof");

l2LiskToken.transfer(_recipient, _amount * LSK_MULTIPLIER);

Expand All @@ -77,7 +77,7 @@ contract L2Claim {
}

/// @notice Claim LSK from a regular account.
/// @param _proof Array of hashes that proves existence of the node.
/// @param _proof Array of hashes that proves existence of the leaf.
/// @param _pubKey Public Key of LSK Address.
/// @param _amount Amount of LSK (In Beddows).
/// @param _recipient Destination address at L2 Chain.
Expand All @@ -92,15 +92,15 @@ contract L2Claim {
external
{
bytes20 lskAddress = bytes20(sha256(abi.encode(_pubKey)));
bytes32 node = doubleKeccak256(abi.encode(lskAddress, _amount, uint32(0), new bytes32[](0), new bytes32[](0)));
bytes32 leaf = doubleKeccak256(abi.encode(lskAddress, _amount, uint32(0), new bytes32[](0), new bytes32[](0)));

verifySignature(_pubKey, _sig.r, _sig.s, keccak256(abi.encode(node, _recipient)));
verifySignature(_pubKey, _sig.r, _sig.s, keccak256(abi.encode(leaf, _recipient)));

claim(lskAddress, _amount, _proof, node, _recipient);
claim(lskAddress, _amount, _proof, leaf, _recipient);
}

/// @notice Claim LSK from a multisig account.
/// @param _proof Array of hashes that proves existence of the node.
/// @param _proof Array of hashes that proves existence of the leaf.
/// @param _lskAddress LSK Address in bytes format.
/// @param _amount Amount of LSK (In Beddows).
/// @param _keys Structs of Mandatory Keys and Optional Keys.
Expand Down Expand Up @@ -128,11 +128,11 @@ contract L2Claim {
numberOfSignatures++;
}

bytes32 node = doubleKeccak256(
bytes32 leaf = doubleKeccak256(
abi.encode(_lskAddress, _amount, numberOfSignatures, _keys.mandatoryKeys, _keys.optionalKeys)
);

bytes32 message = keccak256(abi.encode(node, _recipient));
bytes32 message = keccak256(abi.encode(leaf, _recipient));

for (uint256 i = 0; i < _keys.mandatoryKeys.length; i++) {
verifySignature(_keys.mandatoryKeys[i], _sigs[i].r, _sigs[i].s, message);
Expand All @@ -150,6 +150,6 @@ contract L2Claim {
);
}

claim(_lskAddress, _amount, _proof, node, _recipient);
claim(_lskAddress, _amount, _proof, leaf, _recipient);
}
}
Loading

0 comments on commit 8e41149

Please sign in to comment.