@@ -8,6 +8,7 @@ use alloy_primitives::{address, uint, Address, B256, U256};
88use alloy_sol_types:: SolType ;
99use stylus_sdk:: {
1010 call:: { self , Call , MethodError } ,
11+ storage:: TopLevelStorage ,
1112 stylus_proc:: SolidityError ,
1213} ;
1314
@@ -76,6 +77,7 @@ impl MethodError for ecdsa::Error {
7677///
7778/// # Arguments
7879///
80+ /// * `storage` - Write access to storage.
7981/// * `hash` - Hash of the message.
8082/// * `v` - `v` value from the signature.
8183/// * `r` - `r` value from the signature.
@@ -91,10 +93,16 @@ impl MethodError for ecdsa::Error {
9193/// # Panics
9294///
9395/// * 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 > {
95103 check_if_malleable ( & s) ?;
96104 // 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)
98106}
99107
100108/// Calls `ecrecover` EVM precompile.
@@ -104,6 +112,7 @@ pub fn recover(hash: B256, v: u8, r: B256, s: B256) -> Result<Address, Error> {
104112///
105113/// # Arguments
106114///
115+ /// * `storage` - Write access to storage.
107116/// * `hash` - Hash of the message.
108117/// * `v` - `v` value from the signature.
109118/// * `r` - `r` value from the signature.
@@ -119,7 +128,13 @@ pub fn recover(hash: B256, v: u8, r: B256, s: B256) -> Result<Address, Error> {
119128/// # Panics
120129///
121130/// * 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 > {
123138 let calldata = encode_calldata ( hash, v, r, s) ;
124139
125140 if v == 0 || v == 1 {
@@ -130,8 +145,9 @@ fn _recover(hash: B256, v: u8, r: B256, s: B256) -> Result<Address, Error> {
130145 return Err ( ECDSAInvalidSignature { } . into ( ) ) ;
131146 }
132147
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" ) ;
135151
136152 let recovered = Address :: from_slice ( & recovered[ 12 ..] ) ;
137153
0 commit comments