Skip to content

Allowance interface tweaks #80

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

Merged
merged 8 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trevm"
version = "0.19.6"
version = "0.19.7"
rust-version = "1.83.0"
edition = "2021"
authors = ["init4"]
Expand Down Expand Up @@ -37,6 +37,7 @@ revm = { version = "19.5.0", default-features = false, features = ["std"] }
zenith-types = { version = "0.14" }

dashmap = { version = "6.1.0", optional = true }
tracing = "0.1.41"

[dev-dependencies]
alloy-rlp = { version = "0.3", default-features = false }
Expand All @@ -55,6 +56,7 @@ tokio = { version = "1.39", features = ["macros", "rt-multi-thread"] }

[features]
default = [
"call",
"concurrent-db",
"estimate_gas",
"revm/std",
Expand All @@ -64,6 +66,8 @@ default = [
"revm/secp256k1",
]

call = ["optional_eip3607", "optional_no_base_fee"]

concurrent-db = ["dep:dashmap"]

estimate_gas = ["optional_eip3607", "optional_no_base_fee"]
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ Trevm is useful for:

## Note on Trevm Versioning

Trevm generally uses [semantic versioning](https://semver.org/). However, we
also strive to indicate the MAJOR version of revm in the MINOR version of
Trevm generally uses [semantic versioning](https://semver.org/). While pre-1.0,
we also strive to indicate the MAJOR version of revm in the MINOR version of
trevm. For example, trevm `0.19.x` SHOULD BE compatible with revm `19.x.x`. In
general, we will try to maintain compatibility with the latest revm version,
and will not backport trevm fixes to older trevm or revm versions. It is
generally not advised to use old revm versions, as the EVM is a living spec.

In order to maintain this relationship (that trevm MINOR == revm MAJOR) we will
sometimes make breaking changes in patch versions. This is technically semver
compliant pre-1.0, but will cause build breakage downstream for users of those
features. We will take care to document breaking changes in patch releases
via github release notes.
Comment on lines +40 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good note, this is fine and IMO helpful for users.


## Limitations

Trevm is a work in progress and is not feature complete. In particular, trevm
Expand Down
39 changes: 33 additions & 6 deletions src/est.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ use std::ops::Range;
/// binary searching.
pub(crate) struct SearchRange(Range<u64>);

impl core::fmt::Display for SearchRange {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}..{}", self.0.start, self.0.end)
}
}

impl From<Range<u64>> for SearchRange {
fn from(value: Range<u64>) -> Self {
Self(value)
Expand All @@ -25,7 +31,7 @@ impl SearchRange {

/// Calculate the midpoint of the search range.
pub(crate) const fn midpoint(&self) -> u64 {
(self.0.end - self.0.start) / 2
(self.max() + self.min()) / 2
}

/// Get the start of the search range.
Expand All @@ -38,6 +44,7 @@ impl SearchRange {
self.0.start = min;
}

/// Raise the minimum of the search range, if the candidate is higher.
pub(crate) const fn maybe_raise_min(&mut self, candidate: u64) {
if candidate > self.min() {
self.set_min(candidate);
Expand Down Expand Up @@ -110,11 +117,33 @@ pub enum EstimationResult {
},
}

impl From<&ExecutionResult> for EstimationResult {
fn from(value: &ExecutionResult) -> Self {
impl core::fmt::Display for EstimationResult {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Success { estimation, refund, gas_used, .. } => {
write!(
f,
"Success {{ estimation: {}, refund: {}, gas_used: {}, .. }}",
estimation, refund, gas_used
)
}
Self::Revert { gas_used, .. } => {
write!(f, "Revert {{ gas_used: {}, .. }}", gas_used)
}
Self::Halt { reason, gas_used } => {
write!(f, "Halt {{ reason: {:?}, gas_used: {} }}", reason, gas_used)
}
}
}
}

impl EstimationResult {
/// Initialize the estimation result from an execution result and the gas
/// limit of the transaction that produced the estimation.
pub fn from_limit_and_execution_result(limit: u64, value: &ExecutionResult) -> Self {
match value {
ExecutionResult::Success { gas_used, output, gas_refunded, .. } => Self::Success {
estimation: *gas_used,
estimation: limit,
refund: *gas_refunded,
gas_used: *gas_used,
output: output.clone(),
Expand All @@ -127,9 +156,7 @@ impl From<&ExecutionResult> for EstimationResult {
}
}
}
}

impl EstimationResult {
/// Create a successful estimation result with a gas estimation of 21000.
pub const fn basic_transfer_success(estimation: u64) -> Self {
Self::Success {
Expand Down
Loading