Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compare validator and withdrawal proof state roots #53

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/ExoCapsule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul
error UnregisteredValidator(bytes32 pubkey);
error UnregisteredOrWithdrawnValidatorContainer(bytes32 pubkey);
error FullyWithdrawnValidatorContainer(bytes32 pubkey);
error UnmatchedValidatorAndWithdrawal(bytes32 pubkey);
error UnmatchedValidatorAndWithdrawal(bytes32 validatorStateRoot, bytes32 withdrawalStateRoot);
error NotPartialWithdrawal(bytes32 pubkey);
error BeaconChainOracleNotUpdatedAtTime(address oracle, uint256 timestamp);
error WithdrawalFailure(address withdrawer, address recipient, uint256 amount);
Expand Down Expand Up @@ -152,6 +152,11 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul

provenWithdrawal[validatorPubkey][withdrawalProof.withdrawalIndex] = true;

// Validate if validator and withdrawal proof state roots are the same
if (validatorProof.stateRoot != withdrawalProof.stateRoot) {
revert UnmatchedValidatorAndWithdrawal(validatorProof.stateRoot, withdrawalProof.stateRoot);
}

_verifyValidatorContainer(validatorContainer, validatorProof);
_verifyWithdrawalContainer(withdrawalContainer, withdrawalProof);

Expand Down
12 changes: 6 additions & 6 deletions src/libraries/BeaconChainProofs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ library BeaconChainProofs {
);
bool validExecutionPayloadRoot = isValidExecutionPayloadRoot(proof);
bool validHistoricalSummary = isValidHistoricalSummaryRoot(proof);
bool validWCRootAgainstExecutionPayloadRoot =
isValidWCRootAgainstExecutionPayloadRoot(proof, withdrawalContainerRoot);
bool validWCRootAgainstExecutionPayloadRoot = isValidWCRootAgainstBlockRoot(proof, withdrawalContainerRoot);
if (validExecutionPayloadRoot && validHistoricalSummary && validWCRootAgainstExecutionPayloadRoot) {
valid = true;
}
Expand Down Expand Up @@ -192,10 +191,11 @@ library BeaconChainProofs {
return true;
}

function isValidWCRootAgainstExecutionPayloadRoot(
WithdrawalProof calldata withdrawalProof,
bytes32 withdrawalContainerRoot
) internal view returns (bool) {
function isValidWCRootAgainstBlockRoot(WithdrawalProof calldata withdrawalProof, bytes32 withdrawalContainerRoot)
internal
view
returns (bool)
{
//Next we verify the slot against the blockRoot
require(
Merkle.verifyInclusionSha256({
Expand Down
Loading