Skip to content

Commit

Permalink
Feat/add validate (zerodevapp#73)
Browse files Browse the repository at this point in the history
* feat: implement validateSignature of WeightedECDSAValidator

* fix: init totalWeight as 0 in validateSignature

* Fix validSignature for WeightedECDSAValidator

---------

Co-authored-by: adnpark <[email protected]>
Co-authored-by: Derek Chiang <[email protected]>
  • Loading branch information
3 people authored Jan 29, 2024
1 parent 48479d5 commit 8b258e4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/validator/WeightedECDSAValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,25 @@ contract WeightedECDSAValidator is EIP712, IKernelValidator {
return false;
}

function validateSignature(bytes32, bytes calldata) external pure returns (ValidationData) {
function validateSignature(bytes32 hash, bytes calldata signature) external view returns (ValidationData) {
WeightedECDSAValidatorStorage storage strg = weightedStorage[msg.sender];
if (strg.threshold == 0) {
return SIG_VALIDATION_FAILED;
}

uint256 sigCount = signature.length / 65;
if (sigCount == 0) {
return SIG_VALIDATION_FAILED;
}
uint256 totalWeight = 0;
address signer;
for (uint256 i = 0; i < sigCount; i++) {
signer = ECDSA.recover(hash, signature[i * 65:(i + 1) * 65]);
totalWeight += guardian[signer][msg.sender].weight;
if (totalWeight >= strg.threshold) {
return packValidationData(ValidAfter.wrap(0), ValidUntil.wrap(0));
}
}
return SIG_VALIDATION_FAILED;
}
}

0 comments on commit 8b258e4

Please sign in to comment.