Skip to content

Commit

Permalink
feat: add address(0) check
Browse files Browse the repository at this point in the history
  • Loading branch information
lukema95 committed Nov 4, 2023
1 parent accb3cb commit 91c0e30
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions contracts/zevm/ConnectorZEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ contract ZetaConnectorZEVM is ZetaInterfaces {
error WZETATransferFailed();
error OnlyFungibleModule();
error FailedZetaSent();
error ZeroAddress();

/// @notice Fungible module address.
address public constant FUNGIBLE_MODULE_ADDRESS = payable(0x735b14BB79463307AAcBED86DAf3322B1e6226aB);
Expand All @@ -77,6 +78,7 @@ contract ZetaConnectorZEVM is ZetaInterfaces {
event SetWZETA(address wzeta_);

constructor(address _wzeta) {
if (_wzeta == address(0)) revert ZeroAddress();
wzeta = _wzeta;
}

Expand Down
9 changes: 8 additions & 1 deletion contracts/zevm/SystemContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ contract SystemContract is SystemContractErrors {
* @dev Only fungible module can deploy a system contract.
*/
constructor(address wzeta_, address uniswapv2Factory_, address uniswapv2Router02_) {
if (wzeta_ == address(0) || uniswapv2Factory_ == address(0) || uniswapv2Router02_ == address(0)) revert ZeroAddress();
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule();
wZetaContractAddress = wzeta_;
uniswapv2FactoryAddress = uniswapv2Factory_;
Expand All @@ -72,7 +73,11 @@ contract SystemContract is SystemContractErrors {
bytes calldata message
) external {
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule();
if (target == FUNGIBLE_MODULE_ADDRESS || target == address(this)) revert InvalidTarget();
if (
target == FUNGIBLE_MODULE_ADDRESS ||
target == address(this) ||
target.code.length == 0
) revert InvalidTarget();

IZRC20(zrc20).deposit(target, amount);
zContract(target).onCrossChainCall(context, zrc20, amount, message);
Expand Down Expand Up @@ -132,6 +137,7 @@ contract SystemContract is SystemContractErrors {
* @param zrc20, ZRC20 address.
*/
function setGasCoinZRC20(uint256 chainID, address zrc20) external {
if (zrc20 == address(0)) revert ZeroAddress();
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule();
gasCoinZRC20ByChainId[chainID] = zrc20;
emit SetGasCoin(chainID, zrc20);
Expand All @@ -143,6 +149,7 @@ contract SystemContract is SystemContractErrors {
* @param erc20, pair for uniswap wzeta/erc20.
*/
function setGasZetaPool(uint256 chainID, address erc20) external {
if (erc20 == address(0)) revert ZeroAddress();
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule();
address pool = uniswapv2PairFor(uniswapv2FactoryAddress, wZetaContractAddress, erc20);
gasZetaPoolByChainId[chainID] = pool;
Expand Down
1 change: 1 addition & 0 deletions contracts/zevm/ZRC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ contract ZRC20 is IZRC20, IZRC20Metadata, ZRC20Errors {
uint256 gasLimit_,
address systemContractAddress_
) {
if (systemContractAddress_ == address(0)) revert ZeroAddress();
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule();
_name = name_;
_symbol = symbol_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const _abi = [
name: "WZETATransferFailed",
type: "error",
},
{
inputs: [],
name: "ZeroAddress",
type: "error",
},
{
anonymous: false,
inputs: [
Expand Down Expand Up @@ -200,7 +205,7 @@ const _abi = [
] as const;

const _bytecode =
"0x608060405234801561001057600080fd5b50604051610a51380380610a518339818101604052810190610032919061008d565b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610108565b600081519050610087816100f1565b92915050565b6000602082840312156100a3576100a26100ec565b5b60006100b184828501610078565b91505092915050565b60006100c5826100cc565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600080fd5b6100fa816100ba565b811461010557600080fd5b50565b61093a806101176000396000f3fe6080604052600436106100425760003560e01c8062173d46146100d35780633ce4a5bc146100fe578063eb3bacbd14610129578063ec02690114610152576100ce565b366100ce5760008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146100cc576040517f6e6b6de700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b005b600080fd5b3480156100df57600080fd5b506100e861017b565b6040516100f591906106e5565b60405180910390f35b34801561010a57600080fd5b5061011361019f565b60405161012091906106e5565b60405180910390f35b34801561013557600080fd5b50610150600480360381019061014b91906105bf565b6101b7565b005b34801561015e57600080fd5b5061017960048036038101906101749190610619565b6102aa565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b73735b14bb79463307aacbed86daf3322b1e6226ab81565b73735b14bb79463307aacbed86daf3322b1e6226ab73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610230576040517fea02b3f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507f7325870b05f8f3412c318a35fc6a74feca51ea15811ec7a257676ca4db9d41768160405161029f91906106e5565b60405180910390a150565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd333084608001356040518463ffffffff1660e01b815260040161030b93929190610700565b602060405180830381600087803b15801561032557600080fd5b505af1158015610339573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061035d91906105ec565b610393576040517fa8c6fd4a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d82608001356040518263ffffffff1660e01b81526004016103f091906107b3565b600060405180830381600087803b15801561040a57600080fd5b505af115801561041e573d6000803e3d6000fd5b50505050600073735b14bb79463307aacbed86daf3322b1e6226ab73ffffffffffffffffffffffffffffffffffffffff168260800135604051610460906106d0565b60006040518083038185875af1925050503d806000811461049d576040519150601f19603f3d011682016040523d82523d6000602084013e6104a2565b606091505b50509050806104dd576040517fc7ffc47b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600001353373ffffffffffffffffffffffffffffffffffffffff167f7ec1c94701e09b1652f3e1d307e60c4b9ebf99aff8c2079fd1d8c585e031c4e43285806020019061052b91906107ce565b8760800135886040013589806060019061054591906107ce565b8b8060a0019061055591906107ce565b60405161056a99989796959493929190610737565b60405180910390a35050565b600081359050610585816108d6565b92915050565b60008151905061059a816108ed565b92915050565b600060c082840312156105b6576105b56108a9565b5b81905092915050565b6000602082840312156105d5576105d46108bd565b5b60006105e384828501610576565b91505092915050565b600060208284031215610602576106016108bd565b5b60006106108482850161058b565b91505092915050565b60006020828403121561062f5761062e6108bd565b5b600082013567ffffffffffffffff81111561064d5761064c6108b8565b5b610659848285016105a0565b91505092915050565b61066b8161084d565b82525050565b600061067d8385610831565b935061068a838584610895565b610693836108c2565b840190509392505050565b60006106ab600083610842565b91506106b6826108d3565b600082019050919050565b6106ca8161088b565b82525050565b60006106db8261069e565b9150819050919050565b60006020820190506106fa6000830184610662565b92915050565b60006060820190506107156000830186610662565b6107226020830185610662565b61072f60408301846106c1565b949350505050565b600060c08201905061074c600083018c610662565b818103602083015261075f818a8c610671565b905061076e60408301896106c1565b61077b60608301886106c1565b818103608083015261078e818688610671565b905081810360a08301526107a3818486610671565b90509a9950505050505050505050565b60006020820190506107c860008301846106c1565b92915050565b600080833560016020038436030381126107eb576107ea6108ae565b5b80840192508235915067ffffffffffffffff82111561080d5761080c6108a4565b5b602083019250600182023603831315610829576108286108b3565b5b509250929050565b600082825260208201905092915050565b600081905092915050565b60006108588261086b565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b50565b6108df8161084d565b81146108ea57600080fd5b50565b6108f68161085f565b811461090157600080fd5b5056fea2646970667358221220de77795070b6e9d863f949e5ff84ae67c6e2c498e6ffb04996698d04fcebe44864736f6c63430008070033";
"0x608060405234801561001057600080fd5b50604051610ab8380380610ab8833981810160405281019061003291906100f4565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610099576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505061016f565b6000815190506100ee81610158565b92915050565b60006020828403121561010a57610109610153565b5b6000610118848285016100df565b91505092915050565b600061012c82610133565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600080fd5b61016181610121565b811461016c57600080fd5b50565b61093a8061017e6000396000f3fe6080604052600436106100425760003560e01c8062173d46146100d35780633ce4a5bc146100fe578063eb3bacbd14610129578063ec02690114610152576100ce565b366100ce5760008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146100cc576040517f6e6b6de700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b005b600080fd5b3480156100df57600080fd5b506100e861017b565b6040516100f591906106e5565b60405180910390f35b34801561010a57600080fd5b5061011361019f565b60405161012091906106e5565b60405180910390f35b34801561013557600080fd5b50610150600480360381019061014b91906105bf565b6101b7565b005b34801561015e57600080fd5b5061017960048036038101906101749190610619565b6102aa565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b73735b14bb79463307aacbed86daf3322b1e6226ab81565b73735b14bb79463307aacbed86daf3322b1e6226ab73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610230576040517fea02b3f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507f7325870b05f8f3412c318a35fc6a74feca51ea15811ec7a257676ca4db9d41768160405161029f91906106e5565b60405180910390a150565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd333084608001356040518463ffffffff1660e01b815260040161030b93929190610700565b602060405180830381600087803b15801561032557600080fd5b505af1158015610339573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061035d91906105ec565b610393576040517fa8c6fd4a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d82608001356040518263ffffffff1660e01b81526004016103f091906107b3565b600060405180830381600087803b15801561040a57600080fd5b505af115801561041e573d6000803e3d6000fd5b50505050600073735b14bb79463307aacbed86daf3322b1e6226ab73ffffffffffffffffffffffffffffffffffffffff168260800135604051610460906106d0565b60006040518083038185875af1925050503d806000811461049d576040519150601f19603f3d011682016040523d82523d6000602084013e6104a2565b606091505b50509050806104dd576040517fc7ffc47b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81600001353373ffffffffffffffffffffffffffffffffffffffff167f7ec1c94701e09b1652f3e1d307e60c4b9ebf99aff8c2079fd1d8c585e031c4e43285806020019061052b91906107ce565b8760800135886040013589806060019061054591906107ce565b8b8060a0019061055591906107ce565b60405161056a99989796959493929190610737565b60405180910390a35050565b600081359050610585816108d6565b92915050565b60008151905061059a816108ed565b92915050565b600060c082840312156105b6576105b56108a9565b5b81905092915050565b6000602082840312156105d5576105d46108bd565b5b60006105e384828501610576565b91505092915050565b600060208284031215610602576106016108bd565b5b60006106108482850161058b565b91505092915050565b60006020828403121561062f5761062e6108bd565b5b600082013567ffffffffffffffff81111561064d5761064c6108b8565b5b610659848285016105a0565b91505092915050565b61066b8161084d565b82525050565b600061067d8385610831565b935061068a838584610895565b610693836108c2565b840190509392505050565b60006106ab600083610842565b91506106b6826108d3565b600082019050919050565b6106ca8161088b565b82525050565b60006106db8261069e565b9150819050919050565b60006020820190506106fa6000830184610662565b92915050565b60006060820190506107156000830186610662565b6107226020830185610662565b61072f60408301846106c1565b949350505050565b600060c08201905061074c600083018c610662565b818103602083015261075f818a8c610671565b905061076e60408301896106c1565b61077b60608301886106c1565b818103608083015261078e818688610671565b905081810360a08301526107a3818486610671565b90509a9950505050505050505050565b60006020820190506107c860008301846106c1565b92915050565b600080833560016020038436030381126107eb576107ea6108ae565b5b80840192508235915067ffffffffffffffff82111561080d5761080c6108a4565b5b602083019250600182023603831315610829576108286108b3565b5b509250929050565b600082825260208201905092915050565b600081905092915050565b60006108588261086b565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b50565b6108df8161084d565b81146108ea57600080fd5b50565b6108f68161085f565b811461090157600080fd5b5056fea2646970667358221220e41d0c12235f726d6e4655e2fc086a461bfe911a260779226587d8faaced39d264736f6c63430008070033";

type ZetaConnectorZEVMConstructorParams =
| [signer?: Signer]
Expand Down
Loading

0 comments on commit 91c0e30

Please sign in to comment.