From df9cd627c96cb33e0061e6222368c9d8e81e61a6 Mon Sep 17 00:00:00 2001 From: j75689 Date: Thu, 26 Oct 2023 11:16:12 +0800 Subject: [PATCH] fix: build failed after rebase develop --- contracts/AirDrop.sol | 7 +- contracts/AirDrop.template | 193 ------------------------------------ flatten.sh | 3 +- generate-airdrop.js | 31 ------ genesis-template.json | 2 +- scripts/generate-airdrop.sh | 42 ++++++++ scripts/generate-genesis.js | 1 + scripts/generate.sh | 4 + 8 files changed, 53 insertions(+), 230 deletions(-) delete mode 100644 contracts/AirDrop.template delete mode 100644 generate-airdrop.js create mode 100644 scripts/generate-airdrop.sh diff --git a/contracts/AirDrop.sol b/contracts/AirDrop.sol index 80c49680..838504b5 100644 --- a/contracts/AirDrop.sol +++ b/contracts/AirDrop.sol @@ -12,9 +12,9 @@ import "./MerkleProof.sol"; contract AirDrop is IAirDrop, IParamSubscriber, System { using SafeMath for uint256; - string public constant sourceChainID = "Binance-Chain-Tigris"; // TODO: replace with the real chain id - address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address - bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root + string public constant sourceChainID = "Binance-Chain-Ganges"; + address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; + bytes32 public constant override merkleRoot = 0x0000000000000000000000000000000000000000000000000000000000000000; // This is a packed array of booleans. mapping(bytes32 => bool) private claimedMap; @@ -27,7 +27,6 @@ contract AirDrop is IAirDrop, IParamSubscriber, System { claimedMap[node] = true; } - function claim( uint256 tokenIndex, bytes32 tokenSymbol, uint256 amount, bytes calldata ownerPubKey, bytes calldata ownerSignature, bytes calldata approvalSignature, diff --git a/contracts/AirDrop.template b/contracts/AirDrop.template deleted file mode 100644 index 823cb83d..00000000 --- a/contracts/AirDrop.template +++ /dev/null @@ -1,193 +0,0 @@ -pragma solidity 0.6.4; - -import "./interface/IBEP20.sol"; -import "./interface/ITokenHub.sol"; -import "./interface/IAirDrop.sol"; -import "./interface/IParamSubscriber.sol"; -import "./lib/SafeMath.sol"; -import "./lib/BytesToTypes.sol"; -import "./System.sol"; -import "./MerkleProof.sol"; - -contract AirDrop is IAirDrop, System { - using SafeMath for uint256; - - {% if network == 'local' %} - string public constant sourceChainID = "Binance-Chain-Ganges"; // TODO: replace with the real chain id - address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address - bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root - {% elif network == 'QA' %} - string public constant sourceChainID = "Binance-Chain-Ganges"; // TODO: replace with the real chain id - address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address - bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root - {% elif network == 'testnet' %} - string public constant sourceChainID = "Binance-Chain-Ganges"; // TODO: replace with the real chain id - address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address - bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root - {% else %} - string public constant sourceChainID = "Binance-Chain-Tigris"; // TODO: replace with the real chain id - address public approvalAddress = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa; // TODO: replace with the real address - bytes32 public constant override merkleRoot = 0xad4aa415f872123b71db5d447df6bb417fa72c6a41737a82fdb5665e3edaa7c3; // TODO: replace with the real merkle root - {% endif %} - // This is a packed array of booleans. - mapping(bytes32 => bool) private claimedMap; - - function isClaimed(bytes32 node) public view override returns (bool) { - return claimedMap[node]; - } - - function _setClaimed(bytes32 node) private { - claimedMap[node] = true; - } - - - function claim( - uint256 tokenIndex, bytes32 tokenSymbol, uint256 amount, - bytes calldata ownerPubKey, bytes calldata ownerSignature, bytes calldata approvalSignature, - bytes32[] calldata merkleProof) external override { - // Recover the owner address and check signature. - bytes memory ownerAddr = _verifyTMSignature(ownerPubKey, ownerSignature, _tmSignarueHash(tokenIndex, tokenSymbol, amount, msg.sender)); - // Generate the leaf node of merkle tree. - bytes32 node = keccak256(abi.encodePacked(ownerAddr, tokenIndex, tokenSymbol ,amount)); - - // Check if the token is claimed. - require(isClaimed(node), "AlreadyClaimed"); - - address contractAddr = address(0x00); - // Check if the token is exist. - if (tokenSymbol != "BNB") { - contractAddr = _checkTokenContractExist(tokenSymbol); - } - - // Verify the approval signature. - _verifySignature(msg.sender, ownerSignature, approvalSignature, node); - - // Verify the merkle proof. - require(MerkleProof.verify(merkleProof, merkleRoot, node), "InvalidProof"); - - // Unlock the token from TokenHub. - ITokenHub(TOKEN_HUB_ADDR).unlock(contractAddr, msg.sender, amount); - - // Mark it claimed and send the token. - _setClaimed(node); - - emit Claimed(tokenSymbol, msg.sender, amount); - } - - function _verifySignature(address account, bytes memory ownerSignature, bytes memory approvalSignature, bytes32 extra) private view { - // Ensure the account is not the zero address - require(account != address(0), "InvalidSignature"); - - // Ensure the signature length is correct - require(approvalSignature.length == 65, "InvalidSignature"); - bytes32 r; - bytes32 s; - uint8 v; - assembly { - r := mload(add(approvalSignature, 32)) - s := mload(add(approvalSignature, 64)) - v := byte(0, mload(add(approvalSignature, 96))) - } - if (v < 27) v += 27; - require(v == 27 || v == 28, "InvalidSignature"); - - // Perform the approvalSignature recovery and ensure the recovered signer is the approval account - bytes32 hash = keccak256(abi.encodePacked(sourceChainID, account, ownerSignature, extra)); - require(ecrecover(hash, v, r, s) == approvalAddress, "InvalidSignature"); - } - - function _checkTokenContractExist(bytes32 tokenSymbol) private view returns (address) { - address contractAddr = ITokenHub(TOKEN_HUB_ADDR).getContractAddrByBEP2Symbol(tokenSymbol); - require(contractAddr != address(0x00), "InvalidSymbol"); - - return contractAddr; - } - - function _verifyTMSignature(bytes memory pubKey, bytes memory signature, bytes32 messageHash) internal view returns (bytes memory) { - // Ensure the public key is valid - require(pubKey.length == 33, "Invalid pubKey length"); - // Ensure the signature length is correct - require(signature.length == 64, "Invalid signature length"); - - // assemble input data - bytes memory input = new bytes(129); - _bytesConcat(input, pubKey, 0, 33); - _bytesConcat(input, signature, 33, 64); - _bytesConcat(input, _bytes32toBytes(messageHash), 97, 32); - - - bytes memory output = new bytes(20); - /* solium-disable-next-line */ - assembly { - // call tmSignatureRecover precompile contract - // Contract address: 0x69 - let len := mload(input) - if iszero(staticcall(not(0), 0x69, input, len, output, 20)) { - revert(0, 0) - } - } - - // Additional validation or usage of publicKey here - return output; - } - - function _bytesConcat(bytes memory data, bytes memory _bytes, uint256 index, uint256 len) internal pure { - for (uint i; i contracts/flattened/Tendermi forge flatten contracts/TokenHub.sol > contracts/flattened/TokenHub.sol forge flatten contracts/CrossChain.sol > contracts/flattened/CrossChain.sol forge flatten contracts/TokenManager.sol > contracts/flattened/TokenManager.sol -forge flatten contracts/Staking.sol > contracts/flattened/Staking.sol \ No newline at end of file +forge flatten contracts/Staking.sol > contracts/flattened/Staking.sol +forge flatten contracts/AirDrop.sol > contracts/flattened/AirDrop.sol \ No newline at end of file diff --git a/generate-airdrop.js b/generate-airdrop.js deleted file mode 100644 index 4b18310c..00000000 --- a/generate-airdrop.js +++ /dev/null @@ -1,31 +0,0 @@ -const program = require("commander"); -const fs = require("fs"); -const nunjucks = require("nunjucks"); - - -program.version("0.0.1"); -program.option( - "-t, --template