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: broken eip155 logic in aws signer #2300

Merged
merged 1 commit into from Mar 24, 2023

Conversation

xJonathanLEI
Copy link
Contributor

Motivation

A recent PR (#2260) broke the AWS KMS signer. With the latest version, using the signer would either result in a panic (in debug mode, for subtraction overflow), or simply wrong signatures. Relevant code:

if check_candidate(sig, RecoveryId::from_byte(0).unwrap(), digest, vk) {
EthSig { r, s, v: 0 }
} else if check_candidate(sig, RecoveryId::from_byte(1).unwrap(), digest, vk) {
EthSig { r, s, v: 1 }
} else {
panic!("bad sig");
}
}
/// Modify the v value of a signature to conform to eip155
pub(super) fn apply_eip155(sig: &mut EthSig, chain_id: u64) {
let v = (chain_id * 2 + 35) + ((sig.v - 1) % 2);
sig.v = v;
}

Note that v is already the recovery ID. There's no need to subtract it by 1 (doing so when v is 0 panics). v can also only be 0 or 1, so there's also no need to mod by 2.

Solution

Just use v directly in apply_eip155.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Owner

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

@gakonst gakonst merged commit 36dac58 into gakonst:master Mar 24, 2023
12 of 15 checks passed
@xJonathanLEI xJonathanLEI deleted the fix/aws_signer branch March 24, 2023 18:00
@gyuho
Copy link
Contributor

gyuho commented Mar 25, 2023

Nice! Thanks for the fix @xJonathanLEI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants