Skip to content

Commit

Permalink
fix(protocol): imporve bridge _proveSignalReceived and fix genesis …
Browse files Browse the repository at this point in the history
…test (#15641)

Co-authored-by: David <[email protected]>
  • Loading branch information
dantaik and davidtaikocha authored Feb 2, 2024
1 parent c12e2d7 commit 15f6995
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
35 changes: 17 additions & 18 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ contract Bridge is EssentialContract, IBridge {
bytes32 msgHash = hashMessage(message);
if (isMessageRecalled[msgHash]) revert B_RECALLED_ALREADY();

ISignalService signalService = ISignalService(resolve("signal_service", false));
address signalService = resolve("signal_service", false);

if (!signalService.isSignalSent(address(this), msgHash)) revert B_MESSAGE_NOT_SENT();
if (!ISignalService(signalService).isSignalSent(address(this), msgHash)) {
revert B_MESSAGE_NOT_SENT();
}

bool received = _proveSignalReceived(
signalService, _signalForFailedMessage(msgHash), message.destChainId, proof
Expand Down Expand Up @@ -203,7 +205,7 @@ contract Bridge is EssentialContract, IBridge {

if (messageStatus[msgHash] != Status.NEW) revert B_STATUS_MISMATCH();

ISignalService signalService = ISignalService(resolve("signal_service", false));
address signalService = resolve("signal_service", false);
if (!_proveSignalReceived(signalService, msgHash, message.srcChainId, proof)) {
revert B_NOT_RECEIVED();
}
Expand All @@ -213,8 +215,8 @@ contract Bridge is EssentialContract, IBridge {

// Process message differently based on the target address
if (
message.to == address(0) || message.to == address(this)
|| message.to == address(signalService) || addressBanned[message.to]
message.to == address(0) || message.to == address(this) || message.to == signalService
|| addressBanned[message.to]
) {
// Handle special addresses that don't require actual invocation but
// mark message as DONE
Expand All @@ -233,7 +235,7 @@ contract Bridge is EssentialContract, IBridge {
}

// Update the message status
_updateMessageStatus(signalService, msgHash, status);
_updateMessageStatus(ISignalService(signalService), msgHash, status);

// Determine the refund recipient
address refundTo = message.refundTo == address(0) ? message.owner : message.refundTo;
Expand Down Expand Up @@ -317,7 +319,7 @@ contract Bridge is EssentialContract, IBridge {
if (message.srcChainId != block.chainid) return false;

return _proveSignalReceived(
ISignalService(resolve("signal_service", false)),
resolve("signal_service", false),
_signalForFailedMessage(hashMessage(message)),
message.destChainId,
proof
Expand All @@ -338,10 +340,7 @@ contract Bridge is EssentialContract, IBridge {
{
if (message.destChainId != block.chainid) return false;
return _proveSignalReceived(
ISignalService(resolve("signal_service", false)),
hashMessage(message),
message.srcChainId,
proof
resolve("signal_service", false), hashMessage(message), message.srcChainId, proof
);
}

Expand Down Expand Up @@ -433,7 +432,7 @@ contract Bridge is EssentialContract, IBridge {
/// @param proof The merkle inclusion proof.
/// @return True if the message was received.
function _proveSignalReceived(
ISignalService signalService,
address signalService,
bytes32 signal,
uint64 srcChainId,
bytes calldata proof
Expand All @@ -442,12 +441,12 @@ contract Bridge is EssentialContract, IBridge {
view
returns (bool)
{
return signalService.proveSignalReceived({
srcChainId: srcChainId,
app: resolve(srcChainId, "bridge", false),
signal: signal,
proof: proof
});
bytes memory data = abi.encodeCall(
ISignalService.proveSignalReceived,
(srcChainId, resolve(srcChainId, "bridge", false), signal, proof)
);
(bool success, bytes memory ret) = signalService.staticcall(data);
return success ? abi.decode(ret, (bool)) : false;
}

function _signalForFailedMessage(bytes32 msgHash) private pure returns (bytes32) {
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/contracts/signal/SignalService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ contract SignalService is AuthorizableContract, ISignalService {
}

/// @inheritdoc ISignalService
/// @dev This function may revert.
function proveSignalReceived(
uint64 srcChainId,
address app,
Expand Down
4 changes: 1 addition & 3 deletions packages/protocol/script/DeployUSDCAdaptor.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ contract DeployUSDCAdaptor is DeployCapability {
});

(success, retVal) = erc20Vault.call(
abi.encodeWithSelector(
ERC20Vault.changeBridgedToken.selector, canonicalToken, adaptorProxy
)
abi.encodeCall(ERC20Vault.changeBridgedToken, (canonicalToken, adaptorProxy))
);

if (!success) {
Expand Down

0 comments on commit 15f6995

Please sign in to comment.