-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks for Scilla and ERC-20 transfers
- Loading branch information
1 parent
fdcccd0
commit d368d5b
Showing
6 changed files
with
233 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.28; | ||
|
||
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
contract ERC20FixedSupply is ERC20("token", "TKN") { | ||
constructor() { | ||
_mint(msg.sender, 1_000_000_000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use alloy::{json_abi::JsonAbi, primitives::Bytes}; | ||
use foundry_compilers::{ | ||
artifacts::{ | ||
output_selection::OutputSelection, EvmVersion, GasEstimates, Optimizer, Settings, | ||
SolcInput, Source, | ||
}, | ||
solc::{Solc, SolcLanguage}, | ||
}; | ||
|
||
pub fn compile_contract(path: &str, contract: &str) -> (JsonAbi, Bytes, GasEstimates) { | ||
let full_path = format!("{}/{}", env!("CARGO_MANIFEST_DIR"), path); | ||
let source_path = Path::new(&full_path); | ||
let target_file = tempfile::Builder::new() | ||
.suffix(".sol") | ||
.tempfile() | ||
.unwrap() | ||
.into_temp_path(); | ||
let target_file = target_file.to_path_buf(); | ||
|
||
std::fs::copy(source_path, &target_file).unwrap(); | ||
|
||
let solc_input = SolcInput::new( | ||
SolcLanguage::Solidity, | ||
Source::read_all_files(vec![target_file.clone()]).unwrap(), | ||
Settings { | ||
remappings: vec![format!( | ||
"@openzeppelin/contracts={}/../vendor/openzeppelin-contracts/contracts", | ||
env!("CARGO_MANIFEST_DIR") | ||
) | ||
.parse() | ||
.unwrap()], | ||
optimizer: Optimizer { | ||
enabled: Some(true), | ||
runs: Some(2usize.pow(32) - 1), | ||
details: None, | ||
}, | ||
output_selection: OutputSelection::complete_output_selection(), | ||
..Default::default() | ||
}, | ||
) | ||
.evm_version(EvmVersion::Shanghai); // ensure compatible with EVM version in exec.rs | ||
|
||
let mut solc = Solc::find_or_install(&semver::Version::new(0, 8, 28)).unwrap(); | ||
solc.allow_paths | ||
.insert(PathBuf::from("../vendor/openzeppelin-contracts")); | ||
let mut output = solc.compile_exact(&solc_input).unwrap(); | ||
|
||
if output.has_error() { | ||
for error in output.errors { | ||
eprintln!("{error}"); | ||
} | ||
panic!("failed to compile contract"); | ||
} | ||
|
||
let contract = output | ||
.contracts | ||
.remove(&target_file) | ||
.unwrap() | ||
.remove(contract) | ||
.unwrap(); | ||
let evm = contract.evm.unwrap(); | ||
|
||
( | ||
contract.abi.unwrap(), | ||
evm.bytecode.unwrap().into_bytes().unwrap(), | ||
evm.gas_estimates.unwrap(), | ||
) | ||
} |