Skip to content

Commit

Permalink
Merge branch 'main' into safe-erc20
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNeshi committed Sep 30, 2024
2 parents d47db5a + 5f77db7 commit bf1915a
Show file tree
Hide file tree
Showing 40 changed files with 1,199 additions and 124 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/check-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- name: check openzeppelin-crypto
run: cargo publish -p openzeppelin-crypto --target wasm32-unknown-unknown --dry-run

- name: check openzeppelin-stylus-proc
run: cargo publish -p openzeppelin-stylus-proc --target wasm32-unknown-unknown --dry-run

# TODO: https://github.com/OpenZeppelin/rust-contracts-stylus/issues/291
# - name: check openzeppelin-stylus
# run: cargo publish -p openzeppelin-stylus --target wasm32-unknown-unknown --dry-run
3 changes: 3 additions & 0 deletions .github/workflows/gas-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
with:
key: "gas-bench"

- name: install cargo-stylus
run: cargo install [email protected]

- name: install solc
run: |
curl -LO https://github.com/ethereum/solidity/releases/download/v0.8.24/solc-static-linux
Expand Down
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"contracts",
"contracts-proc",
"lib/crypto",
"lib/motsu",
"lib/motsu-proc",
Expand All @@ -22,6 +23,7 @@ members = [
]
default-members = [
"contracts",
"contracts-proc",
"lib/crypto",
"lib/motsu",
"lib/motsu-proc",
Expand All @@ -48,7 +50,6 @@ resolver = "2"
authors = ["OpenZeppelin"]
edition = "2021"
license = "MIT"
keywords = ["arbitrum", "ethereum", "stylus"]
repository = "https://github.com/OpenZeppelin/rust-contracts-stylus"
version = "0.1.0-rc"

Expand Down Expand Up @@ -92,6 +93,7 @@ rand = "0.8.5"
regex = "1.10.4"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
tokio = { version = "1.12.0", features = ["full"] }
futures = "0.3.30"

# procedural macros
syn = { version = "2.0.58", features = ["full"] }
Expand All @@ -100,6 +102,7 @@ quote = "1.0.35"

# members
openzeppelin-stylus = { path = "contracts" }
openzeppelin-stylus-proc = { path = "contracts-proc" }
openzeppelin-crypto = { path = "lib/crypto" }
motsu = { path = "lib/motsu"}
motsu-proc = { path = "lib/motsu-proc", version = "0.1.0" }
Expand Down
1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ openzeppelin-stylus.workspace = true
alloy-primitives = { workspace = true, features = ["tiny-keccak"] }
alloy.workspace = true
tokio.workspace = true
futures.workspace = true
eyre.workspace = true
koba.workspace = true
e2e.workspace = true
Expand Down
38 changes: 30 additions & 8 deletions benches/src/access_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use alloy::{
};
use e2e::{receipt, Account};

use crate::report::Report;
use crate::{
report::{ContractReport, FunctionReport},
CacheOpt,
};

sol!(
#[sol(rpc)]
Expand All @@ -33,7 +36,22 @@ const ROLE: [u8; 32] =
const NEW_ADMIN_ROLE: [u8; 32] =
hex!("879ce0d4bfd332649ca3552efe772a38d64a315eb70ab69689fd309c735946b5");

pub async fn bench() -> eyre::Result<Report> {
pub async fn bench() -> eyre::Result<ContractReport> {
let receipts = run_with(CacheOpt::None).await?;
let report = receipts
.into_iter()
.try_fold(ContractReport::new("AccessControl"), ContractReport::add)?;

let cached_receipts = run_with(CacheOpt::Bid(0)).await?;
let report = cached_receipts
.into_iter()
.try_fold(report, ContractReport::add_cached)?;

Ok(report)
}
pub async fn run_with(
cache_opt: CacheOpt,
) -> eyre::Result<Vec<FunctionReport>> {
let alice = Account::new().await?;
let alice_addr = alice.address();
let alice_wallet = ProviderBuilder::new()
Expand All @@ -50,7 +68,8 @@ pub async fn bench() -> eyre::Result<Report> {
.wallet(EthereumWallet::from(bob.signer.clone()))
.on_http(bob.url().parse()?);

let contract_addr = deploy(&alice).await;
let contract_addr = deploy(&alice, cache_opt).await?;

let contract = AccessControl::new(contract_addr, &alice_wallet);
let contract_bob = AccessControl::new(contract_addr, &bob_wallet);

Expand All @@ -66,14 +85,17 @@ pub async fn bench() -> eyre::Result<Report> {
(setRoleAdminCall::SIGNATURE, receipt!(contract.setRoleAdmin(ROLE.into(), NEW_ADMIN_ROLE.into()))?),
];

let report = receipts
receipts
.into_iter()
.try_fold(Report::new("AccessControl"), Report::add)?;
Ok(report)
.map(FunctionReport::new)
.collect::<eyre::Result<Vec<_>>>()
}

async fn deploy(account: &Account) -> Address {
async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args = AccessControl::constructorCall {};
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "access-control", Some(args)).await
crate::deploy(account, "access-control", Some(args), cache_opt).await
}
40 changes: 32 additions & 8 deletions benches/src/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use alloy::{
use alloy_primitives::U256;
use e2e::{receipt, Account};

use crate::report::Report;
use crate::{
report::{ContractReport, FunctionReport},
CacheOpt,
};

sol!(
#[sol(rpc)]
Expand Down Expand Up @@ -39,7 +42,23 @@ const TOKEN_NAME: &str = "Test Token";
const TOKEN_SYMBOL: &str = "TTK";
const CAP: U256 = uint!(1_000_000_U256);

pub async fn bench() -> eyre::Result<Report> {
pub async fn bench() -> eyre::Result<ContractReport> {
let reports = run_with(CacheOpt::None).await?;
let report = reports
.into_iter()
.try_fold(ContractReport::new("Erc20"), ContractReport::add)?;

let cached_reports = run_with(CacheOpt::Bid(0)).await?;
let report = cached_reports
.into_iter()
.try_fold(report, ContractReport::add_cached)?;

Ok(report)
}

pub async fn run_with(
cache_opt: CacheOpt,
) -> eyre::Result<Vec<FunctionReport>> {
let alice = Account::new().await?;
let alice_addr = alice.address();
let alice_wallet = ProviderBuilder::new()
Expand All @@ -56,7 +75,8 @@ pub async fn bench() -> eyre::Result<Report> {
.wallet(EthereumWallet::from(bob.signer.clone()))
.on_http(bob.url().parse()?);

let contract_addr = deploy(&alice).await;
let contract_addr = deploy(&alice, cache_opt).await?;

let contract = Erc20::new(contract_addr, &alice_wallet);
let contract_bob = Erc20::new(contract_addr, &bob_wallet);

Expand All @@ -79,17 +99,21 @@ pub async fn bench() -> eyre::Result<Report> {
(transferFromCall::SIGNATURE, receipt!(contract_bob.transferFrom(alice_addr, bob_addr, uint!(4_U256)))?),
];

let report =
receipts.into_iter().try_fold(Report::new("Erc20"), Report::add)?;
Ok(report)
receipts
.into_iter()
.map(FunctionReport::new)
.collect::<eyre::Result<Vec<_>>>()
}

async fn deploy(account: &Account) -> Address {
async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args = Erc20Example::constructorCall {
name_: TOKEN_NAME.to_owned(),
symbol_: TOKEN_SYMBOL.to_owned(),
cap_: CAP,
};
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "erc20", Some(args)).await
crate::deploy(account, "erc20", Some(args), cache_opt).await
}
40 changes: 32 additions & 8 deletions benches/src/erc721.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use alloy::{
};
use e2e::{receipt, Account};

use crate::report::Report;
use crate::{
report::{ContractReport, FunctionReport},
CacheOpt,
};

sol!(
#[sol(rpc)]
Expand All @@ -29,7 +32,23 @@ sol!(

sol!("../examples/erc721/src/constructor.sol");

pub async fn bench() -> eyre::Result<Report> {
pub async fn bench() -> eyre::Result<ContractReport> {
let reports = run_with(CacheOpt::None).await?;
let report = reports
.into_iter()
.try_fold(ContractReport::new("Erc721"), ContractReport::add)?;

let cached_reports = run_with(CacheOpt::Bid(0)).await?;
let report = cached_reports
.into_iter()
.try_fold(report, ContractReport::add_cached)?;

Ok(report)
}

pub async fn run_with(
cache_opt: CacheOpt,
) -> eyre::Result<Vec<FunctionReport>> {
let alice = Account::new().await?;
let alice_addr = alice.address();
let alice_wallet = ProviderBuilder::new()
Expand All @@ -41,7 +60,8 @@ pub async fn bench() -> eyre::Result<Report> {
let bob = Account::new().await?;
let bob_addr = bob.address();

let contract_addr = deploy(&alice).await;
let contract_addr = deploy(&alice, cache_opt).await?;

let contract = Erc721::new(contract_addr, &alice_wallet);

let token_1 = uint!(1_U256);
Expand Down Expand Up @@ -70,13 +90,17 @@ pub async fn bench() -> eyre::Result<Report> {
(burnCall::SIGNATURE, receipt!(contract.burn(token_1))?),
];

let report =
receipts.into_iter().try_fold(Report::new("Erc721"), Report::add)?;
Ok(report)
receipts
.into_iter()
.map(FunctionReport::new)
.collect::<eyre::Result<Vec<_>>>()
}

async fn deploy(account: &Account) -> Address {
async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args = Erc721Example::constructorCall {};
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "erc721", Some(args)).await
crate::deploy(account, "erc721", Some(args), cache_opt).await
}
Loading

0 comments on commit bf1915a

Please sign in to comment.