@@ -8,6 +8,7 @@ use alloy_primitives::{address, uint, Address, B256, U256};
8
8
use alloy_sol_types:: SolType ;
9
9
use stylus_sdk:: {
10
10
call:: { self , Call , MethodError } ,
11
+ storage:: TopLevelStorage ,
11
12
stylus_proc:: SolidityError ,
12
13
} ;
13
14
@@ -76,6 +77,7 @@ impl MethodError for ecdsa::Error {
76
77
///
77
78
/// # Arguments
78
79
///
80
+ /// * `storage` - Write access to storage.
79
81
/// * `hash` - Hash of the message.
80
82
/// * `v` - `v` value from the signature.
81
83
/// * `r` - `r` value from the signature.
@@ -91,10 +93,16 @@ impl MethodError for ecdsa::Error {
91
93
/// # Panics
92
94
///
93
95
/// * If the `ecrecover` precompile fails to execute.
94
- pub fn recover ( hash : B256 , v : u8 , r : B256 , s : B256 ) -> Result < Address , Error > {
96
+ pub fn recover (
97
+ storage : & mut impl TopLevelStorage ,
98
+ hash : B256 ,
99
+ v : u8 ,
100
+ r : B256 ,
101
+ s : B256 ,
102
+ ) -> Result < Address , Error > {
95
103
check_if_malleable ( & s) ?;
96
104
// If the signature is valid (and not malleable), return the signer address.
97
- _recover ( hash, v, r, s)
105
+ _recover ( storage , hash, v, r, s)
98
106
}
99
107
100
108
/// Calls `ecrecover` EVM precompile.
@@ -104,6 +112,7 @@ pub fn recover(hash: B256, v: u8, r: B256, s: B256) -> Result<Address, Error> {
104
112
///
105
113
/// # Arguments
106
114
///
115
+ /// * `storage` - Write access to storage.
107
116
/// * `hash` - Hash of the message.
108
117
/// * `v` - `v` value from the signature.
109
118
/// * `r` - `r` value from the signature.
@@ -119,7 +128,13 @@ pub fn recover(hash: B256, v: u8, r: B256, s: B256) -> Result<Address, Error> {
119
128
/// # Panics
120
129
///
121
130
/// * If the `ecrecover` precompile fails to execute.
122
- fn _recover ( hash : B256 , v : u8 , r : B256 , s : B256 ) -> Result < Address , Error > {
131
+ fn _recover (
132
+ storage : & mut impl TopLevelStorage ,
133
+ hash : B256 ,
134
+ v : u8 ,
135
+ r : B256 ,
136
+ s : B256 ,
137
+ ) -> Result < Address , Error > {
123
138
let calldata = encode_calldata ( hash, v, r, s) ;
124
139
125
140
if v == 0 || v == 1 {
@@ -130,8 +145,9 @@ fn _recover(hash: B256, v: u8, r: B256, s: B256) -> Result<Address, Error> {
130
145
return Err ( ECDSAInvalidSignature { } . into ( ) ) ;
131
146
}
132
147
133
- let recovered = call:: static_call ( Call :: new ( ) , ECRECOVER_ADDR , & calldata)
134
- . expect ( "should call `ecrecover` precompile" ) ;
148
+ let recovered =
149
+ call:: static_call ( Call :: new_in ( storage) , ECRECOVER_ADDR , & calldata)
150
+ . expect ( "should call `ecrecover` precompile" ) ;
135
151
136
152
let recovered = Address :: from_slice ( & recovered[ 12 ..] ) ;
137
153
0 commit comments