Skip to content

Commit

Permalink
enhance: add whitelabe relayers
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro committed Oct 11, 2022
1 parent 537dc4a commit c0a7af0
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 21 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ Ganache-cli: v6.10.1
Generate contracts for testing:
```shell script
# the first account of ganache
node generate-system.js --mock true
node generate-system.js --mock true --network local
node generate-systemReward.js --mock true
node generate-validatorset.js --mock true
node generate-system.js --mock true
node generate-slash.js --mock true
node generate-crosschain.js --mock true
node generate-tokenhub.js --mock true
Expand Down
2 changes: 1 addition & 1 deletion contracts/CrossChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{
return (true, packageType, relayFee, msgBytes);
}

function handlePackage(bytes calldata payload, bytes calldata proof, uint64 height, uint64 packageSequence, uint8 channelId) onlyInit onlyRelayer
function handlePackage(bytes calldata payload, bytes calldata proof, uint64 height, uint64 packageSequence, uint8 channelId) onlyInit onlyRelayer onlyWhiteLableRelayer
sequenceInOrder(packageSequence, channelId) blockSynced(height) channelSupported(channelId) headerInOrder(height, channelId) external {
bytes memory payloadLocal = payload; // fix error: stack too deep, try removing local variables
bytes memory proofLocal = proof; // fix error: stack too deep, try removing local variables
Expand Down
2 changes: 1 addition & 1 deletion contracts/CrossChain.template
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{
return (true, packageType, relayFee, msgBytes);
}

function handlePackage(bytes calldata payload, bytes calldata proof, uint64 height, uint64 packageSequence, uint8 channelId) onlyInit onlyRelayer
function handlePackage(bytes calldata payload, bytes calldata proof, uint64 height, uint64 packageSequence, uint8 channelId) onlyInit onlyRelayer onlyWhiteLableRelayer
sequenceInOrder(packageSequence, channelId) blockSynced(height) channelSupported(channelId) headerInOrder(height, channelId) external {
bytes memory payloadLocal = payload; // fix error: stack too deep, try removing local variables
bytes memory proofLocal = proof; // fix error: stack too deep, try removing local variables
Expand Down
7 changes: 7 additions & 0 deletions contracts/System.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ contract System {
_;
}


modifier onlyWhiteLableRelayer() {
require(msg.sender == 0xb005741528b86F5952469d80A8614591E3c5B632 || msg.sender == 0x446AA6E0DC65690403dF3F127750da1322941F3e, "the msg sender is not a whitelabel relayer");
_;
}


modifier onlyTokenManager() {
require(msg.sender == TOKEN_MANAGER_ADDR, "the msg sender must be tokenManager");
_;
Expand Down
22 changes: 22 additions & 0 deletions contracts/System.template
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,28 @@ contract System {
_;
}

{% if network == 'local' %}
modifier onlyWhiteLableRelayer() {
require(msg.sender == 0xA904540818AC9c47f2321F97F1069B9d8746c6DB || msg.sender == 0x316b2Fa7C8a2ab7E21110a4B3f58771C01A71344, "the msg sender is not a whitelabel relayer");
_;
}
{% elif network == 'QA' %}
modifier onlyWhiteLableRelayer() {
require(msg.sender == 0x88cb4D8F77742c24d647BEf8049D3f3C56067cDD || msg.sender == 0x42D596440775C90db8d9187b47650986E1063493, "the msg sender is not a whitelabel relayer");
_;
}
{% elif network == 'testnet' %}
modifier onlyWhiteLableRelayer() {
require(msg.sender == 0x9fB29AAc15b9A4B7F17c3385939b007540f4d791 || msg.sender == 0x37B8516a0F88E65D677229b402ec6C1e0E333004, "the msg sender is not a whitelabel relayer");
_;
}
{% else %}
modifier onlyWhiteLableRelayer() {
require(msg.sender == 0xb005741528b86F5952469d80A8614591E3c5B632 || msg.sender == 0x446AA6E0DC65690403dF3F127750da1322941F3e, "the msg sender is not a whitelabel relayer");
_;
}
{% endif %}

modifier onlyTokenManager() {
require(msg.sender == TOKEN_MANAGER_ADDR, "the msg sender must be tokenManager");
_;
Expand Down
2 changes: 1 addition & 1 deletion contracts/TendermintLightClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{
emit initConsensusState(initialHeight, cs.appHash);
}

function syncTendermintHeader(bytes calldata header, uint64 height) external onlyRelayer returns (bool) {
function syncTendermintHeader(bytes calldata header, uint64 height) external onlyRelayer onlyWhiteLableRelayer returns (bool) {
require(submitters[height] == address(0x0), "can't sync duplicated header");
require(height > initialHeight, "can't sync header before initialHeight");

Expand Down
2 changes: 1 addition & 1 deletion contracts/TendermintLightClient.template
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract TendermintLightClient is ILightClient, System, IParamSubscriber{
emit initConsensusState(initialHeight, cs.appHash);
}

function syncTendermintHeader(bytes calldata header, uint64 height) external onlyRelayer returns (bool) {
function syncTendermintHeader(bytes calldata header, uint64 height) external onlyRelayer onlyWhiteLableRelayer returns (bool) {
require(submitters[height] == address(0x0), "can't sync duplicated header");
require(height > initialHeight, "can't sync header before initialHeight");

Expand Down
4 changes: 4 additions & 0 deletions generate-genesis.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ program.option(
""
)

program.option("--network <network>",
"network",
"mainnet");

program.option(
"--initBurnRatio <initBurnRatio>",
"initBurnRatio",
Expand Down
5 changes: 5 additions & 0 deletions generate-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ program.option(
"System.sol",
"./contracts/System.sol"
)
program.option("--network <network>",
"network",
"mainnet");

program.option("--mock <mock>",
"if use mock",
false);
Expand All @@ -28,6 +32,7 @@ const data = {
fromChainId: program.fromChainId,
bscChainId: program.bscChainId,
mock: program.mock,
network: program.network,
};
const templateString = fs.readFileSync(program.template).toString();
const resultString = nunjucks.renderString(templateString, data);
Expand Down
22 changes: 11 additions & 11 deletions genesis.json

Large diffs are not rendered by default.

Loading

0 comments on commit c0a7af0

Please sign in to comment.