@@ -93,8 +93,18 @@ contract ObolValidatorManagerTest is Test {
9393 principalThreshold
9494 );
9595
96- ovmETH.deposit {value: INITIAL_DEPOSIT_AMOUNT}(new bytes (0 ), new bytes (0 ), new bytes (0 ), bytes32 (0 ));
97- ovmETH_OR.deposit {value: INITIAL_DEPOSIT_AMOUNT}(new bytes (0 ), new bytes (0 ), new bytes (0 ), bytes32 (0 ));
96+ ovmETH.deposit {value: INITIAL_DEPOSIT_AMOUNT}(
97+ new bytes (0 ),
98+ _withdrawalCredentials (ovmETH, 0x02 ),
99+ new bytes (0 ),
100+ bytes32 (0 )
101+ );
102+ ovmETH_OR.deposit {value: INITIAL_DEPOSIT_AMOUNT}(
103+ new bytes (0 ),
104+ _withdrawalCredentials (ovmETH_OR, 0x02 ),
105+ new bytes (0 ),
106+ bytes32 (0 )
107+ );
98108 }
99109
100110 function testDefaultParameters () public view {
@@ -113,25 +123,70 @@ contract ObolValidatorManagerTest is Test {
113123 uint256 depositAmount = 1 ether ;
114124 vm.expectEmit (true , true , true , true );
115125 emit PrincipalStakeAmountUpdated (amountOfPrincipalStake + depositAmount, amountOfPrincipalStake);
116- ovmETH.deposit {value: depositAmount}(new bytes (0 ), new bytes ( 0 ), new bytes (0 ), bytes32 (0 ));
126+ ovmETH.deposit {value: depositAmount}(new bytes (0 ), _withdrawalCredentials (ovmETH, 0x02 ), new bytes (0 ), bytes32 (0 ));
117127 assertEq (address (depositMock).balance, depositMockBalance + depositAmount);
118128 assertEq (ovmETH.amountOfPrincipalStake (), amountOfPrincipalStake + depositAmount);
119129 }
120130
131+ function testDepositWithEth1WithdrawalCredentials () public {
132+ uint256 amountOfPrincipalStake = ovmETH.amountOfPrincipalStake ();
133+ uint256 depositAmount = 1 ether ;
134+ ovmETH.deposit {value: depositAmount}(new bytes (0 ), _withdrawalCredentials (ovmETH, 0x01 ), new bytes (0 ), bytes32 (0 ));
135+ assertEq (ovmETH.amountOfPrincipalStake (), amountOfPrincipalStake + depositAmount);
136+ }
137+
121138 function testCannotDeposit () public {
122139 // unauthorized
123140 address _user = vm.addr (0x5 );
124141 vm.deal (_user, 1 ether);
125142 ovmETH.grantRoles (_user, ovmETH.WITHDRAWAL_ROLE ()); // unrelated role
126143 vm.startPrank (_user);
127144 vm.expectRevert (bytes4 (0x82b42900 ));
128- ovmETH.deposit {value: 1 ether }(new bytes (0 ), new bytes ( 0 ), new bytes (0 ), bytes32 (0 ));
145+ ovmETH.deposit {value: 1 ether }(new bytes (0 ), _withdrawalCredentials (ovmETH, 0x02 ), new bytes (0 ), bytes32 (0 ));
129146 vm.stopPrank ();
130147
131148 // unauthorized for owner after renounce
132149 ovmETH.renounceOwnership ();
133150 vm.expectRevert (bytes4 (0x82b42900 ));
151+ ovmETH.deposit {value: 1 ether }(new bytes (0 ), _withdrawalCredentials (ovmETH, 0x02 ), new bytes (0 ), bytes32 (0 ));
152+ }
153+
154+ function testCannotDepositWithInvalidWithdrawalCredentials () public {
155+ // empty credentials
156+ vm.expectRevert (IObolValidatorManager.InvalidDeposit_WithdrawalCredentials.selector );
134157 ovmETH.deposit {value: 1 ether }(new bytes (0 ), new bytes (0 ), new bytes (0 ), bytes32 (0 ));
158+
159+ // wrong length: 31 bytes
160+ vm.expectRevert (IObolValidatorManager.InvalidDeposit_WithdrawalCredentials.selector );
161+ ovmETH.deposit {value: 1 ether }(new bytes (0 ), new bytes (31 ), new bytes (0 ), bytes32 (0 ));
162+
163+ // wrong length: 33 bytes (valid credentials + 1 extra byte)
164+ bytes memory tooLong = abi.encodePacked (_withdrawalCredentials (ovmETH, 0x02 ), bytes1 (0 ));
165+ vm.expectRevert (IObolValidatorManager.InvalidDeposit_WithdrawalCredentials.selector );
166+ ovmETH.deposit {value: 1 ether }(new bytes (0 ), tooLong, new bytes (0 ), bytes32 (0 ));
167+
168+ // wrong prefix: 0x00 (BLS credentials)
169+ vm.expectRevert (IObolValidatorManager.InvalidDeposit_WithdrawalCredentials.selector );
170+ ovmETH.deposit {value: 1 ether }(new bytes (0 ), _withdrawalCredentials (ovmETH, 0x00 ), new bytes (0 ), bytes32 (0 ));
171+
172+ // wrong prefix: 0x03
173+ vm.expectRevert (IObolValidatorManager.InvalidDeposit_WithdrawalCredentials.selector );
174+ ovmETH.deposit {value: 1 ether }(new bytes (0 ), _withdrawalCredentials (ovmETH, 0x03 ), new bytes (0 ), bytes32 (0 ));
175+
176+ // wrong address: credentials commit to an address other than the OVM
177+ bytes memory wrongAddress = abi.encodePacked (bytes1 (0x02 ), bytes11 (0 ), makeAddr ("attacker " ));
178+ vm.expectRevert (IObolValidatorManager.InvalidDeposit_WithdrawalCredentials.selector );
179+ ovmETH.deposit {value: 1 ether }(new bytes (0 ), wrongAddress, new bytes (0 ), bytes32 (0 ));
180+
181+ // non-zero padding bytes
182+ bytes memory dirtyPadding = abi.encodePacked (bytes1 (0x02 ), bytes11 (uint88 (1 )), address (ovmETH));
183+ vm.expectRevert (IObolValidatorManager.InvalidDeposit_WithdrawalCredentials.selector );
184+ ovmETH.deposit {value: 1 ether }(new bytes (0 ), dirtyPadding, new bytes (0 ), bytes32 (0 ));
185+ }
186+
187+ /// Builds withdrawal credentials committing to the given OVM: prefix + 11 zero bytes + OVM address
188+ function _withdrawalCredentials (ObolValidatorManager ovm , bytes1 prefix ) internal pure returns (bytes memory ) {
189+ return abi.encodePacked (prefix, bytes11 (0 ), address (ovm));
135190 }
136191
137192 function testSetBeneficiaryRecipient () public {
@@ -725,7 +780,7 @@ contract ObolValidatorManagerTest is Test {
725780 function testCan_distributeToBothRecipients () public {
726781 // First deposit of 32eth is done in setUp()
727782 uint256 secondDeposit = 64 ether ;
728- ovmETH.deposit {value: secondDeposit}(new bytes (0 ), new bytes ( 0 ), new bytes (0 ), bytes32 (0 ));
783+ ovmETH.deposit {value: secondDeposit}(new bytes (0 ), _withdrawalCredentials (ovmETH, 0x02 ), new bytes (0 ), bytes32 (0 ));
729784 uint256 rewardPayout = 4 ether ;
730785 address (ovmETH).safeTransferETH (INITIAL_DEPOSIT_AMOUNT + secondDeposit + rewardPayout);
731786
@@ -783,7 +838,7 @@ contract ObolValidatorManagerTest is Test {
783838 ObolValidatorManagerReentrancy re = new ObolValidatorManagerReentrancy ();
784839
785840 ovmETH = ovmFactory.createObolValidatorManager (address (this ), address (re), rewardsRecipient, 1e9 );
786- ovmETH.deposit {value: 1 ether }(new bytes (0 ), new bytes ( 0 ), new bytes (0 ), bytes32 (0 ));
841+ ovmETH.deposit {value: 1 ether }(new bytes (0 ), _withdrawalCredentials (ovmETH, 0x02 ), new bytes (0 ), bytes32 (0 ));
787842 address (ovmETH).safeTransferETH (33 ether);
788843
789844 vm.expectRevert (SafeTransferLib.ETHTransferFailed.selector );
@@ -944,7 +999,7 @@ contract ObolValidatorManagerTest is Test {
944999 );
9451000
9461001 uint256 _totalETHAmount = uint256 (_numDeposits) * uint256 (_ethAmount);
947- ovm.deposit {value: _totalETHAmount}(new bytes (0 ), new bytes ( 0 ), new bytes (0 ), bytes32 (0 ));
1002+ ovm.deposit {value: _totalETHAmount}(new bytes (0 ), _withdrawalCredentials (ovm, 0x02 ), new bytes (0 ), bytes32 (0 ));
9481003
9491004 /// test eth
9501005 for (uint256 i = 0 ; i < _numDeposits; i++ ) {
@@ -993,7 +1048,7 @@ contract ObolValidatorManagerTest is Test {
9931048 );
9941049
9951050 uint256 _totalETHAmount = uint256 (_numDeposits) * uint256 (_ethAmount);
996- ovm.deposit {value: _totalETHAmount}(new bytes (0 ), new bytes ( 0 ), new bytes (0 ), bytes32 (0 ));
1051+ ovm.deposit {value: _totalETHAmount}(new bytes (0 ), _withdrawalCredentials (ovm, 0x02 ), new bytes (0 ), bytes32 (0 ));
9971052
9981053 for (uint256 i = 0 ; i < _numDeposits; i++ ) {
9991054 address (ovm).safeTransferETH (_ethAmount);
0 commit comments