Skip to content

Commit

Permalink
remove uptime message check against source chain
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Nov 1, 2024
1 parent 93b7c1d commit 33380bd
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 27 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions contracts/validator-manager/PoSValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ abstract contract PoSValidatorManager is
revert InvalidWarpMessage();
}

if (warpMessage.sourceChainID != WARP_MESSENGER.getBlockchainID()) {
revert InvalidWarpSourceChainID(warpMessage.sourceChainID);
// The sender is required to be the zero address so that we know the validator node
// signed the proof directly, rather than as an arbitrary on-chain message
if (warpMessage.originSenderAddress != address(0)) {
revert InvalidWarpOriginSenderAddress(warpMessage.originSenderAddress);
}
if (warpMessage.originSenderAddress != address(0)) {
revert InvalidWarpOriginSenderAddress(warpMessage.originSenderAddress);
Expand Down
2 changes: 1 addition & 1 deletion contracts/validator-manager/UptimeMessageSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Specification:
| `uptime` | `uint64` | 8 byte |
| | | 46 bytes |

This is defined within `Subnet-EVM` [here](https://github.com/ava-labs/subnet-evm/blob/323eb0c7dd7204521e662a3a355fe78a0e19c0be/warp/messages/validator_uptime.go#L14-L19).
This is defined within `Subnet-EVM` [here](https://github.com/ava-labs/subnet-evm/blob/323eb0c7dd7204521e662a3a355fe78a0e19c0be/warp/messages/validator_uptime.go#L14-L19). The `ValidationUptimeMessage` must be included as an `AddressedPayload` with the `sourceAddress` set to an empty byte array, to prove that it did not originate as an arbitrary on-chain message. The `sourceChainID` does not need to be specified, as the origin chain is implicitly authenticated by validating the `validationID`.
21 changes: 0 additions & 21 deletions contracts/validator-manager/tests/PoSValidatorManagerTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,9 @@ abstract contract PoSValidatorManagerTest is ValidatorManagerTest {
posValidatorManager.initializeEndValidation(validationID, true, 0);
}

function testInvalidUptimeChainID() public {
bytes32 validationID = _registerDefaultValidator();

_mockGetUptimeWarpMessage(new bytes(0), true);
_mockGetBlockchainID(posValidatorManager.P_CHAIN_BLOCKCHAIN_ID());
vm.warp(DEFAULT_REGISTRATION_TIMESTAMP + DEFAULT_MINIMUM_STAKE_DURATION);
vm.expectRevert(
abi.encodeWithSelector(
ValidatorManager.InvalidWarpSourceChainID.selector, DEFAULT_SOURCE_BLOCKCHAIN_ID
)
);
posValidatorManager.initializeEndValidation(validationID, true, 0);
}

function testInvalidUptimeSenderAddress() public {
bytes32 validationID = _registerDefaultValidator();

_mockGetBlockchainID();
vm.mockCall(
WARP_PRECOMPILE_ADDRESS,
abi.encodeWithSelector(IWarpMessenger.getVerifiedWarpMessage.selector, uint32(0)),
Expand Down Expand Up @@ -246,7 +231,6 @@ abstract contract PoSValidatorManagerTest is ValidatorManagerTest {
function testInvalidUptimeValidationID() public {
bytes32 validationID = _registerDefaultValidator();

_mockGetBlockchainID();
vm.mockCall(
WARP_PRECOMPILE_ADDRESS,
abi.encodeWithSelector(IWarpMessenger.getVerifiedWarpMessage.selector, uint32(0)),
Expand Down Expand Up @@ -1106,7 +1090,6 @@ abstract contract PoSValidatorManagerTest is ValidatorManagerTest {
bytes memory uptimeMsg1 =
ValidatorMessages.packValidationUptimeMessage(validationID, uptime1);
_mockGetUptimeWarpMessage(uptimeMsg1, true);
_mockGetBlockchainID();

vm.expectEmit(true, true, true, true, address(validatorManager));
emit UptimeUpdated(validationID, uptime1);
Expand All @@ -1120,7 +1103,6 @@ abstract contract PoSValidatorManagerTest is ValidatorManagerTest {
bytes memory uptimeMsg2 =
ValidatorMessages.packValidationUptimeMessage(validationID, uptime2);
_mockGetUptimeWarpMessage(uptimeMsg2, true);
_mockGetBlockchainID();

vm.expectEmit(true, true, true, true, address(validatorManager));
emit ValidatorRemovalInitialized(
Expand All @@ -1144,7 +1126,6 @@ abstract contract PoSValidatorManagerTest is ValidatorManagerTest {
(DEFAULT_COMPLETION_TIMESTAMP - DEFAULT_REGISTRATION_TIMESTAMP) * uptimePercentage / 100
);
_mockGetUptimeWarpMessage(uptimeMsg, true);
_mockGetBlockchainID();

vm.expectRevert(
abi.encodeWithSelector(
Expand Down Expand Up @@ -1201,7 +1182,6 @@ abstract contract PoSValidatorManagerTest is ValidatorManagerTest {
(DEFAULT_COMPLETION_TIMESTAMP - DEFAULT_REGISTRATION_TIMESTAMP) * uptimePercentage / 100
);
_mockGetUptimeWarpMessage(uptimeMsg, true);
_mockGetBlockchainID();

vm.expectEmit(true, true, true, true, address(validatorManager));
emit ValidatorRemovalInitialized(
Expand Down Expand Up @@ -1468,7 +1448,6 @@ abstract contract PoSValidatorManagerTest is ValidatorManagerTest {

if (includeUptime) {
_mockGetUptimeWarpMessage(uptimePayload, true);
_mockGetBlockchainID();
}
_initializeEndDelegation(sender, delegationID, endDelegationTimestamp, includeUptime, force);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ abstract contract ValidatorManagerTest is Test {
_mockSendWarpMessage(setWeightMessage, bytes32(0));
if (includeUptime) {
_mockGetUptimeWarpMessage(uptimeMessage, true);
_mockGetBlockchainID();
}

vm.warp(completionTimestamp);
Expand Down

0 comments on commit 33380bd

Please sign in to comment.