File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
contracts/crypto-verify/src Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ pub fn query_verify_ethereum(
99
99
Some ( pair) => pair,
100
100
None => return Err ( StdError :: generic_err ( "Signature must not be empty" ) ) ,
101
101
} ;
102
- let recovery = v - 27 ;
102
+ let recovery = get_recovery_param ( * v ) ? ;
103
103
104
104
// Verification
105
105
let calculated_pubkey = deps. api . secp256k1_recover_pubkey ( & hash, rs, recovery) ?;
@@ -151,6 +151,16 @@ fn ethereum_address(pubkey: &[u8]) -> StdResult<String> {
151
151
Ok ( out)
152
152
}
153
153
154
+ fn get_recovery_param ( v : u8 ) -> StdResult < u8 > {
155
+ // See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
156
+ // for how `v` is composed.
157
+ match v {
158
+ 27 => Ok ( 0 ) ,
159
+ 28 => Ok ( 1 ) ,
160
+ _ => Err ( StdError :: generic_err ( "Values of v other than 27 and 28 not supported. Replay protection (EIP-155) cannot be used here." ) )
161
+ }
162
+ }
163
+
154
164
#[ cfg( test) ]
155
165
mod tests {
156
166
use super :: * ;
You can’t perform that action at this time.
0 commit comments