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

feat: Turn All Call::new_in into Call::new (i.e. Stop Supporting Reentrancy) #440

Merged
merged 14 commits into from
Dec 12, 2024
Merged
2 changes: 1 addition & 1 deletion contracts/src/finance/vesting_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
) -> Result<U256, Self::Error>;
}

#[public]

Check warning on line 349 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unexpected `cfg` condition value: `export-abi`

Check warning on line 349 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`

Check warning on line 349 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`
impl IVestingWallet for VestingWallet {
type Error = Error;

Expand Down Expand Up @@ -420,7 +420,7 @@

let owner = self.ownable.owner();

call(Call::new_in(self).value(amount), owner, &[])?;
call(Call::new().value(amount), owner, &[])?;

evm::log(EtherReleased { amount });

Expand Down
4 changes: 2 additions & 2 deletions contracts/src/token/erc1155/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
) -> Result<(), Self::Error>;
}

#[public]

Check warning on line 387 in contracts/src/token/erc1155/mod.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unexpected `cfg` condition value: `export-abi`

Check warning on line 387 in contracts/src/token/erc1155/mod.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`

Check warning on line 387 in contracts/src/token/erc1155/mod.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`
impl IErc1155 for Erc1155 {
type Error = Error;

Expand Down Expand Up @@ -786,7 +786,7 @@
/// interface id or returned with error, then the error
/// [`Error::InvalidReceiver`] is returned.
fn _check_on_erc1155_received(
&mut self,
&self,

Check warning on line 789 in contracts/src/token/erc1155/mod.rs

View workflow job for this annotation

GitHub Actions / stable / clippy

[clippy] reported by reviewdog 🐶 warning: unused `self` argument --> contracts/src/token/erc1155/mod.rs:789:9 | 789 | &self, | ^^^^^ | = help: consider refactoring to an associated function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_self = note: `-W clippy::unused-self` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::unused_self)]` Raw Output: contracts/src/token/erc1155/mod.rs:789:9:w:warning: unused `self` argument --> contracts/src/token/erc1155/mod.rs:789:9 | 789 | &self, | ^^^^^ | = help: consider refactoring to an associated function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_self = note: `-W clippy::unused-self` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::unused_self)]` __END__

Check warning on line 789 in contracts/src/token/erc1155/mod.rs

View workflow job for this annotation

GitHub Actions / beta / clippy

[clippy] reported by reviewdog 🐶 warning: unused `self` argument --> contracts/src/token/erc1155/mod.rs:789:9 | 789 | &self, | ^^^^^ | = help: consider refactoring to an associated function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_self = note: `-W clippy::unused-self` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::unused_self)]` Raw Output: contracts/src/token/erc1155/mod.rs:789:9:w:warning: unused `self` argument --> contracts/src/token/erc1155/mod.rs:789:9 | 789 | &self, | ^^^^^ | = help: consider refactoring to an associated function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_self = note: `-W clippy::unused-self` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::unused_self)]` __END__
SarveshLimaye marked this conversation as resolved.
Show resolved Hide resolved
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
operator: Address,
from: Address,
to: Address,
Expand All @@ -798,7 +798,7 @@
}

let receiver = IERC1155Receiver::new(to);
let call = Call::new_in(self);
let call = Call::new();
let result = match details.transfer {
Transfer::Single { id, value } => receiver
.on_erc_1155_received(call, operator, from, id, value, data),
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/token/erc20/extensions/permit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
/// BorrowMut<Self>)`. Should be fixed in the future by the Stylus team.
unsafe impl<T: IEip712 + StorageType> TopLevelStorage for Erc20Permit<T> {}

#[public]

Check warning on line 87 in contracts/src/token/erc20/extensions/permit.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unexpected `cfg` condition value: `export-abi`

Check warning on line 87 in contracts/src/token/erc20/extensions/permit.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`

Check warning on line 87 in contracts/src/token/erc20/extensions/permit.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`
impl<T: IEip712 + StorageType> Erc20Permit<T> {
/// Returns the current nonce for `owner`.
///
Expand Down Expand Up @@ -174,7 +174,7 @@

let hash: B256 = self.eip712.hash_typed_data_v4(struct_hash);

let signer: Address = ecdsa::recover(self, hash, v, r, s)?;
let signer: Address = ecdsa::recover(hash, v, r, s)?;

if signer != owner {
return Err(ERC2612InvalidSigner { signer, owner }.into());
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/token/erc721/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ impl Erc721 {
/// interface id or returned with error, then the error
/// [`Error::InvalidReceiver`] is returned.
pub fn _check_on_erc721_received(
&mut self,
&self,
operator: Address,
from: Address,
to: Address,
Expand All @@ -1122,7 +1122,7 @@ impl Erc721 {
}

let receiver = IERC721Receiver::new(to);
let call = Call::new_in(self);
let call = Call::new();
let result = receiver.on_erc_721_received(
call,
operator,
Expand Down
7 changes: 2 additions & 5 deletions contracts/src/utils/cryptography/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use alloy_sol_types::{sol, SolType};
use stylus_sdk::{
call::{self, Call, MethodError},
storage::TopLevelStorage,
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
stylus_proc::SolidityError,
};

0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -84,19 +83,18 @@
/// * If the recovered address is `Address::ZERO`, then the error
/// [`Error::InvalidSignature`] is returned.
///
/// # Panics

Check warning on line 86 in contracts/src/utils/cryptography/ecdsa.rs

View workflow job for this annotation

GitHub Actions / nightly / fmt

Diff in /home/runner/work/rust-contracts-stylus/rust-contracts-stylus/contracts/src/utils/cryptography/ecdsa.rs
///
/// * If the `ecrecover` precompile fails to execute.
pub fn recover(
storage: &mut impl TopLevelStorage,
hash: B256,
v: u8,
r: B256,
s: B256,
) -> Result<Address, Error> {
check_if_malleable(&s)?;
// If the signature is valid (and not malleable), return the signer address.
_recover(storage, hash, v, r, s)
_recover(hash, v, r, s)
}

/// Calls `ecrecover` EVM precompile.
Expand All @@ -119,11 +117,10 @@
/// * If the recovered address is `Address::ZERO`, then the error
/// [`Error::InvalidSignature`] is returned.
///
/// # Panics

Check warning on line 120 in contracts/src/utils/cryptography/ecdsa.rs

View workflow job for this annotation

GitHub Actions / nightly / fmt

Diff in /home/runner/work/rust-contracts-stylus/rust-contracts-stylus/contracts/src/utils/cryptography/ecdsa.rs
///
/// * If the `ecrecover` precompile fails to execute.
fn _recover(
storage: &mut impl TopLevelStorage,
hash: B256,
v: u8,
r: B256,
Expand All @@ -136,11 +133,11 @@
// but following the Solidity tests
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/utils/cryptography/ECDSA.test.js
// it should return `ECDSAInvalidSignature` error.
return Err(ECDSAInvalidSignature {}.into());

Check warning on line 136 in contracts/src/utils/cryptography/ecdsa.rs

View workflow job for this annotation

GitHub Actions / nightly / fmt

Diff in /home/runner/work/rust-contracts-stylus/rust-contracts-stylus/contracts/src/utils/cryptography/ecdsa.rs
}

let recovered =
call::static_call(Call::new_in(storage), ECRECOVER_ADDR, &calldata)
call::static_call(Call::new(), ECRECOVER_ADDR, &calldata)
.expect("should call `ecrecover` precompile");

let recovered = Address::from_slice(&recovered[12..]);
Expand Down
2 changes: 1 addition & 1 deletion examples/ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl ECDSAExample {
r: B256,
s: B256,
) -> Result<Address, Vec<u8>> {
let signer = ecdsa::recover(self, hash, v, r, s)?;
let signer = ecdsa::recover(hash, v, r, s)?;
Ok(signer)
}
}
Loading