Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing 'verify' function in DVN contract #69

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 60 additions & 69 deletions messagelib/contracts/uln/dvn/DVN.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

pragma solidity ^0.8.20;

import { ILayerZeroUltraLightNodeV2 } from "@layerzerolabs/lz-evm-v1-0.7/contracts/interfaces/ILayerZeroUltraLightNodeV2.sol";
import {ILayerZeroUltraLightNodeV2} from
"@layerzerolabs/lz-evm-v1-0.7/contracts/interfaces/ILayerZeroUltraLightNodeV2.sol";

import { Worker } from "../../Worker.sol";
import { MultiSig } from "./MultiSig.sol";
import { IDVN } from "../interfaces/IDVN.sol";
import { IDVNFeeLib } from "../interfaces/IDVNFeeLib.sol";
import { IReceiveUlnE2 } from "../interfaces/IReceiveUlnE2.sol";
import {Worker} from "../../Worker.sol";
import {MultiSig} from "./MultiSig.sol";
import {IDVN} from "../interfaces/IDVN.sol";
import {IDVNFeeLib} from "../interfaces/IDVNFeeLib.sol";
import {IReceiveUlnE2} from "../interfaces/IReceiveUlnE2.sol";

struct ExecuteParam {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need comments of this struct according NatSpec

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't modify anything there. So, it's as it was.

uint32 vid;
Expand Down Expand Up @@ -142,7 +143,7 @@ contract DVN is Worker, MultiSig, IDVN {

// generate and validate hash
bytes32 hash = hashCallData(_param.vid, _param.target, _param.callData, _param.expiration);
(bool sigsValid, ) = verifySignatures(hash, _param.signatures);
(bool sigsValid,) = verifySignatures(hash, _param.signatures);
if (!sigsValid) {
revert DVN_InvalidSignatures();
}
Expand All @@ -165,6 +166,18 @@ contract DVN is Worker, MultiSig, IDVN {
emit SetDstConfig(_params);
}

/// @dev for dvn to verify the payload by calling `verify` fn of ReceiveUln302 contract;
/// @param _receiveLib the receiveUln302 address on local chain (same as where dvn is on) to be called
/// when dvn calls `verify` to verify the sent message.
/// E.g. If message is sent from Ethereum to Polygon, then DVN (on Polygon) has to verify the
/// sent message by calling verify function of `ReceiveUln302` (on Polygon).
function verify(address _receiveLib, bytes calldata _packetHeader, bytes32 _payloadHash, uint64 _confirmations)
external
onlySelfOrAdmin(ADMIN_ROLE)
{
IReceiveUlnE2(_receiveLib).verify(_packetHeader, _payloadHash, _confirmations);
}

/// @dev takes a list of instructions and executes them in order
/// @dev if any of the instructions fail, it will emit an error event and continue to execute the rest of the instructions
/// @param _params array of ExecuteParam, includes target, callData, expiration, signatures
Expand All @@ -185,7 +198,7 @@ contract DVN is Worker, MultiSig, IDVN {
bytes32 hash = hashCallData(param.vid, param.target, param.callData, param.expiration);

// 3. check signatures
(bool sigsValid, ) = verifySignatures(hash, param.signatures);
(bool sigsValid,) = verifySignatures(hash, param.signatures);
if (!sigsValid) {
emit VerifySignaturesFailed(i);
continue;
Expand Down Expand Up @@ -232,17 +245,15 @@ contract DVN is Worker, MultiSig, IDVN {
/// @dev dvn network can reject job from _sender by adding/removing them from allowlist/denylist
/// @param _param assign job param
/// @param _options dvn options
function assignJob(
AssignJobParam calldata _param,
bytes calldata _options
) external payable onlyRole(MESSAGE_LIB_ROLE) onlyAcl(_param.sender) returns (uint256 totalFee) {
function assignJob(AssignJobParam calldata _param, bytes calldata _options)
external
payable
onlyRole(MESSAGE_LIB_ROLE)
onlyAcl(_param.sender)
returns (uint256 totalFee)
{
IDVNFeeLib.FeeParams memory feeParams = IDVNFeeLib.FeeParams(
priceFeed,
_param.dstEid,
_param.confirmations,
_param.sender,
quorum,
defaultMultiplierBps
priceFeed, _param.dstEid, _param.confirmations, _param.sender, quorum, defaultMultiplierBps
);
totalFee = IDVNFeeLib(workerFeeLib).getFeeOnSend(feeParams, dstConfig[_param.dstEid], _options);
}
Expand All @@ -253,20 +264,14 @@ contract DVN is Worker, MultiSig, IDVN {
/// @param //_outboundProofType outbound proof type
/// @param _confirmations block confirmations
/// @param _sender message sender address
function assignJob(
uint16 _dstEid,
uint16 /*_outboundProofType*/,
uint64 _confirmations,
address _sender
) external onlyRole(MESSAGE_LIB_ROLE) onlyAcl(_sender) returns (uint256 totalFee) {
IDVNFeeLib.FeeParams memory params = IDVNFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
function assignJob(uint16 _dstEid, uint16, /*_outboundProofType*/ uint64 _confirmations, address _sender)
external
onlyRole(MESSAGE_LIB_ROLE)
onlyAcl(_sender)
returns (uint256 totalFee)
{
IDVNFeeLib.FeeParams memory params =
IDVNFeeLib.FeeParams(priceFeed, _dstEid, _confirmations, _sender, quorum, defaultMultiplierBps);
// ULNV2 does not have dvn options
totalFee = IDVNFeeLib(workerFeeLib).getFeeOnSend(params, dstConfig[_dstEid], bytes(""));
emit VerifierFeePaid(totalFee);
Expand All @@ -280,20 +285,14 @@ contract DVN is Worker, MultiSig, IDVN {
/// @param _sender message sender address
/// @param _options dvn options
/// @return fee fee in native amount
function getFee(
uint32 _dstEid,
uint64 _confirmations,
address _sender,
bytes calldata _options
) external view onlyAcl(_sender) returns (uint256 fee) {
IDVNFeeLib.FeeParams memory params = IDVNFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
function getFee(uint32 _dstEid, uint64 _confirmations, address _sender, bytes calldata _options)
external
view
onlyAcl(_sender)
returns (uint256 fee)
{
IDVNFeeLib.FeeParams memory params =
IDVNFeeLib.FeeParams(priceFeed, _dstEid, _confirmations, _sender, quorum, defaultMultiplierBps);
return IDVNFeeLib(workerFeeLib).getFee(params, dstConfig[_dstEid], _options);
}

Expand All @@ -303,33 +302,26 @@ contract DVN is Worker, MultiSig, IDVN {
/// @param //_outboundProofType outbound proof type
/// @param _confirmations block confirmations
/// @param _sender message sender address
function getFee(
uint16 _dstEid,
uint16 /*_outboundProofType*/,
uint64 _confirmations,
address _sender
) public view onlyAcl(_sender) returns (uint256 fee) {
IDVNFeeLib.FeeParams memory params = IDVNFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
function getFee(uint16 _dstEid, uint16, /*_outboundProofType*/ uint64 _confirmations, address _sender)
public
view
onlyAcl(_sender)
returns (uint256 fee)
{
IDVNFeeLib.FeeParams memory params =
IDVNFeeLib.FeeParams(priceFeed, _dstEid, _confirmations, _sender, quorum, defaultMultiplierBps);
return IDVNFeeLib(workerFeeLib).getFee(params, dstConfig[_dstEid], bytes(""));
}

/// @param _target target address
/// @param _callData call data
/// @param _expiration expiration timestamp
/// @return hash of above
function hashCallData(
uint32 _vid,
address _target,
bytes calldata _callData,
uint256 _expiration
) public pure returns (bytes32) {
function hashCallData(uint32 _vid, address _target, bytes calldata _callData, uint256 _expiration)
public
pure
returns (bytes32)
{
return keccak256(abi.encodePacked(_vid, _target, _expiration, _callData));
}

Expand All @@ -342,8 +334,7 @@ contract DVN is Worker, MultiSig, IDVN {
/// @return true if should check hash
function _shouldCheckHash(bytes4 _functionSig) internal pure returns (bool) {
// never check for these selectors to save gas
return
_functionSig != IReceiveUlnE2.verify.selector && // 0x0223536e, replaying won't change the state
_functionSig != ILayerZeroUltraLightNodeV2.updateHash.selector; // 0x704316e5, replaying will be revert at uln
return _functionSig != IReceiveUlnE2.verify.selector // 0x0223536e, replaying won't change the state
&& _functionSig != ILayerZeroUltraLightNodeV2.updateHash.selector; // 0x704316e5, replaying will be revert at uln
}
}
1 change: 1 addition & 0 deletions messagelib/contracts/uln/interfaces/IDVN.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ interface IDVN is IWorker, ILayerZeroDVN {
event SetDstConfig(DstConfigParam[] params);

function dstConfig(uint32 _dstEid) external view returns (uint64, uint16, uint128);
function verify(address _receiveLibRemote, bytes calldata _packetHeader, bytes32 _payloadHash,uint64 _confirmations) external;
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@
"packageManager": "[email protected]",
"engines": {
"node": ">=18.12.0"
},
"dependencies": {
"corepack": "^0.26.0"
}
}
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ __metadata:
dependencies:
"@layerzerolabs/prettier-config-next": "npm:^2.0.1"
"@layerzerolabs/solhint-config": "npm:^2.0.1"
corepack: "npm:^0.26.0"
prettier: "npm:^3.1.0"
rimraf: "npm:^5.0.5"
solhint: "npm:^4.0.0"
Expand Down Expand Up @@ -2781,6 +2782,19 @@ __metadata:
languageName: node
linkType: hard

"corepack@npm:^0.26.0":
version: 0.26.0
resolution: "corepack@npm:0.26.0"
bin:
corepack: ./dist/corepack.js
pnpm: ./dist/pnpm.js
pnpx: ./dist/pnpx.js
yarn: ./dist/yarn.js
yarnpkg: ./dist/yarnpkg.js
checksum: b882da8ff56e4755abe9193206ff92851f3daaa045d493afe6cab058e8484e914974aa04882d05ce1db7f4226f50017c75c7c644bf8d3c9dab6986bd9419d19a
languageName: node
linkType: hard

"cors@npm:^2.8.1":
version: 2.8.5
resolution: "cors@npm:2.8.5"
Expand Down