save target address in state and use it to verify forwarding request (#75)

* save target address in state and use it to verify forwarding request

* Fix to Multideliveries/Multiforwards

* complete merge
This commit is contained in:
derpy-duck 2023-02-14 10:33:55 -05:00 committed by GitHub
parent 727483ce10
commit ba8a09d6f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

View File

@ -30,6 +30,7 @@ contract CoreRelayer is CoreRelayerGovernance {
error InsufficientFunds(string reason);
error MsgValueTooLow(); // msg.value must cover the budget specified
error NonceIsZero();
error ForwardRequestFromWrongAddress();
error NoDeliveryInProcess();
error CantRequestMultipleForwards();
error RelayProviderDoesNotSupportTargetChain();
@ -256,6 +257,10 @@ contract CoreRelayer is CoreRelayerGovernance {
revert NonceIsZero();
}
if (msg.sender != lockedTargetAddress()) {
revert ForwardRequestFromWrongAddress();
}
bool foundRolloverChain = false;
IRelayProvider selectedProvider = IRelayProvider(container.relayProviderAddress);
@ -398,6 +403,7 @@ contract CoreRelayer is CoreRelayerGovernance {
revert ReentrantCall();
}
setContractLock(true);
setLockedTargetAddress(fromWormholeFormat(internalInstruction.targetAddress));
// store gas budget pre target invocation to calculate unused gas budget
uint256 preGas = gasleft();
@ -441,10 +447,7 @@ contract CoreRelayer is CoreRelayerGovernance {
// sequence =
// wormhole.publishMessage{value: wormhole.messageFee()}(0, encodeDeliveryStatus(status), consistencyLevel());
ForwardingRequest memory forwardingRequest = getForwardingRequest();
if (
forwardingRequest.isValid
&& (forwardingRequest.sender == fromWormholeFormat(internalInstruction.targetAddress))
) {
if (forwardingRequest.isValid) {
(, success) = emitForward(weiToRefund, forwardingRequest);
if (success) {
emit Delivery(

View File

@ -60,4 +60,8 @@ contract CoreRelayerGetters is CoreRelayerState {
function isContractLocked() internal view returns (bool) {
return _state.contractLock;
}
function lockedTargetAddress() internal view returns (address) {
return _state.targetAddress;
}
}

View File

@ -54,6 +54,10 @@ contract CoreRelayerSetters is CoreRelayerState, Context {
_state.contractLock = status;
}
function setLockedTargetAddress(address targetAddress) internal {
_state.targetAddress = targetAddress;
}
function setEvmChainId(uint256 evmChainId) internal {
if (evmChainId != block.chainid) {
revert InvalidEvmChainId();

View File

@ -17,6 +17,8 @@ contract CoreRelayerStorage {
Provider provider;
// delivery lock for reentrancy protection
bool contractLock;
// the target address that is currently being delivered to (if contractLock = true)
address targetAddress;
// EIP-155 Chain ID
uint256 evmChainId;
// consumed governance VAAs