Skip to content

Commit

Permalink
rescue: Finishes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmerkleplant committed Oct 10, 2024
1 parent 14a0c20 commit aac35c4
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 208 deletions.
40 changes: 1 addition & 39 deletions script/rescue/Rescuer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,40 +77,8 @@ contract Rescuer is Auth {
uint32 pokeDataAge,
IScribe.ECDSAData memory opPokeSig
) external auth {
_suck(opScribe, pubKey, registrationSig, pokeDataAge, opPokeSig);
}

/// @notice Rescues ETH from multiple ScribeOptimistic instances `opScribes`.
///
/// @dev Note that `opScribes` MUST be deactivated.
/// @dev Note that validator key pair SHALL be only used once and generated
/// via a CSPRNG.
///
/// @dev Only callable by auth'ed address.
function suck(
address[] memory opScribes,
LibSecp256k1.Point memory pubKey,
IScribe.ECDSAData memory registrationSig,
uint32 pokeDataAge,
IScribe.ECDSAData memory opPokeSig
) external auth {
for (uint i = 0; i < opScribes.length; i++) {
_suck(opScribes[i], pubKey, registrationSig, pokeDataAge, opPokeSig);
}
}

function _suck(
address opScribe,
LibSecp256k1.Point memory pubKey,
IScribe.ECDSAData memory registrationSig,
uint32 pokeDataAge,
IScribe.ECDSAData memory opPokeSig
) internal {
require(IAuth(opScribe).authed(address(this)));

address validator = pubKey.toAddress();
uint8 validatorId = uint8(uint(uint160(validator)) >> 152);

uint balanceBefore = address(this).balance;

// Fail if instance has feeds lifted, ie is not deactivated.
Expand All @@ -134,18 +102,12 @@ contract Rescuer is Auth {
IScribeOptimistic(opScribe).opPoke(pokeData, schnorrSig, opPokeSig);

// Perform opChallenge.
bool ok = IScribeOptimistic(opScribe).opChallenge(schnorrSig);
require(ok);

// Drop validator again.
IScribe(opScribe).drop(validatorId);
IScribeOptimistic(opScribe).opChallenge(schnorrSig);

// Compute amount of ETH received as challenge reward.
uint amount = address(this).balance - balanceBefore;

// Emit event.
emit Recovered(msg.sender, opScribe, amount);
}


}
Loading

0 comments on commit aac35c4

Please sign in to comment.