From 3d077f8ee520a116028711391c323c7badd1f2c6 Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:54:08 +0800 Subject: [PATCH] refactor(protocol): slightly improve EssentialContract (#18445) --- .../contracts/shared/common/EssentialContract.sol | 5 +++++ .../contracts/shared/signal/SignalService.sol | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/protocol/contracts/shared/common/EssentialContract.sol b/packages/protocol/contracts/shared/common/EssentialContract.sol index 654393b21e7..70320ea9623 100644 --- a/packages/protocol/contracts/shared/common/EssentialContract.sol +++ b/packages/protocol/contracts/shared/common/EssentialContract.sol @@ -71,6 +71,11 @@ abstract contract EssentialContract is UUPSUpgradeable, Ownable2StepUpgradeable, _; } + modifier nonZeroBytes32(bytes32 _value) { + require(_value != 0, ZERO_VALUE()); + _; + } + /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); diff --git a/packages/protocol/contracts/shared/signal/SignalService.sol b/packages/protocol/contracts/shared/signal/SignalService.sol index 8b4416eda8c..f7432392bb7 100644 --- a/packages/protocol/contracts/shared/signal/SignalService.sol +++ b/packages/protocol/contracts/shared/signal/SignalService.sol @@ -120,7 +120,7 @@ contract SignalService is EssentialContract, ISignalService { ) public view - nonZeroValue(uint256(_chainData)) + nonZeroBytes32(_chainData) returns (bool) { bytes32 signal = signalForChainData(_chainId, _kind, _blockId); @@ -193,8 +193,8 @@ contract SignalService is EssentialContract, ISignalService { view virtual nonZeroAddr(_app) - nonZeroValue(uint256(_signal)) - nonZeroValue(uint256(_value)) + nonZeroBytes32(_signal) + nonZeroBytes32(_value) returns (bytes32) { return LibTrieProof.verifyMerkleProof( @@ -234,8 +234,8 @@ contract SignalService is EssentialContract, ISignalService { ) private nonZeroAddr(_app) - nonZeroValue(uint256(_signal)) - nonZeroValue(uint256(_value)) + nonZeroBytes32(_signal) + nonZeroBytes32(_value) returns (bytes32 slot_) { slot_ = getSignalSlot(uint64(block.chainid), _app, _signal); @@ -276,7 +276,7 @@ contract SignalService is EssentialContract, ISignalService { private view nonZeroAddr(_app) - nonZeroValue(uint256(_signal)) + nonZeroBytes32(_signal) returns (bytes32 value_) { bytes32 slot = getSignalSlot(uint64(block.chainid), _app, _signal); @@ -295,7 +295,7 @@ contract SignalService is EssentialContract, ISignalService { private view nonZeroAddr(_app) - nonZeroValue(uint256(_signal)) + nonZeroBytes32(_signal) returns (CacheAction[] memory actions) { HopProof[] memory hopProofs = abi.decode(_proof, (HopProof[]));