Skip to content

Commit e4a1226

Browse files
committed
evm: Per-chain thresholds
1 parent d249162 commit e4a1226

14 files changed

+337
-184
lines changed

evm/script/helpers/DeployWormholeNttBase.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ contract DeployWormholeNttBase is ParseNttConfig {
100100
}
101101

102102
// Hardcoded to one since these scripts handle Wormhole-only deployments.
103-
INttManager(nttManager).setThreshold(1);
103+
// TODO: We need the sourceChainId to set the threshold. Also need to enable sending and receiving.
104+
// INttManager(nttManager).setThreshold(1);
104105
console2.log("Threshold set on NttManager: %d", uint256(1));
105106
}
106107

evm/src/NttManager/ManagerBase.sol

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ abstract contract ManagerBase is
166166
) internal returns (bytes32, bool) {
167167
bytes32 digest = TransceiverStructs.nttManagerMessageDigest(sourceChainId, message);
168168

169-
if (!isMessageApproved(digest)) {
169+
if (!isMessageApproved(sourceChainId, digest)) {
170170
revert MessageNotApproved(digest);
171171
}
172172

@@ -284,15 +284,16 @@ abstract contract ManagerBase is
284284
}
285285

286286
/// @inheritdoc IManagerBase
287-
function getThreshold() public view returns (uint8) {
288-
return _getThresholdStorage().num;
287+
/// @dev This is here because it is defined in IManagerBase.
288+
function getThreshold(
289+
uint16 sourceChainId
290+
) public view returns (uint8) {
291+
return _getPerChainRecvTransceiverDataStorage()[sourceChainId].threshold;
289292
}
290293

291294
/// @inheritdoc IManagerBase
292-
function isMessageApproved(
293-
bytes32 digest
294-
) public view returns (bool) {
295-
uint8 threshold = getThreshold();
295+
function isMessageApproved(uint16 sourceChainId, bytes32 digest) public view returns (bool) {
296+
uint8 threshold = getThreshold(sourceChainId);
296297
return messageAttestations(digest) >= threshold && threshold > 0;
297298
}
298299

@@ -401,20 +402,9 @@ abstract contract ManagerBase is
401402
}
402403

403404
/// @inheritdoc IManagerBase
404-
function setThreshold(
405-
uint8 threshold
406-
) external onlyOwner {
407-
if (threshold == 0) {
408-
revert ZeroThreshold();
409-
}
410-
411-
_Threshold storage _threshold = _getThresholdStorage();
412-
uint8 oldThreshold = _threshold.num;
413-
414-
_threshold.num = threshold;
415-
_checkThresholdInvariants();
416-
417-
emit ThresholdChanged(oldThreshold, threshold);
405+
/// @dev This is here because it is defined in IManagerBase.
406+
function setThreshold(uint16 sourceChainId, uint8 threshold) external onlyOwner {
407+
_setThreshold(sourceChainId, threshold);
418408
}
419409

420410
// =============== Internal ==============================================================
@@ -484,20 +474,4 @@ abstract contract ManagerBase is
484474
);
485475
}
486476
}
487-
488-
function _checkThresholdInvariants() internal view {
489-
uint8 threshold = _getThresholdStorage().num;
490-
_NumTransceivers memory numTransceivers = _getNumTransceiversStorage();
491-
492-
// invariant: threshold <= enabledTransceivers.length
493-
if (threshold > numTransceivers.enabled) {
494-
revert ThresholdTooHigh(threshold, numTransceivers.enabled);
495-
}
496-
497-
if (numTransceivers.registered > 0) {
498-
if (threshold == 0) {
499-
revert ZeroThreshold();
500-
}
501-
}
502-
}
503477
}

evm/src/NttManager/NttManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ contract NttManager is INttManager, RateLimiter, ManagerBase {
192192
// Compute manager message digest and record transceiver attestation.
193193
bytes32 nttManagerMessageHash = _recordTransceiverAttestation(sourceChainId, payload);
194194

195-
if (isMessageApproved(nttManagerMessageHash)) {
195+
if (isMessageApproved(sourceChainId, nttManagerMessageHash)) {
196196
executeMsg(sourceChainId, sourceNttManagerAddress, payload);
197197
}
198198
}

0 commit comments

Comments
 (0)