Skip to content

Commit

Permalink
Skip rehashing function signatures (#965)
Browse files Browse the repository at this point in the history
`ethercontract-rs` is computing and storing all the function signature
hashes when generating the contract bindings.
Unfortunately we used `ethabi::function::encode_inputs()` which does not
memoize the hash and therefore has to recompute it every time.
This PR makes simply makes sure that we don't rehash the signature every
time.

### Test Plan
Unit tests still work and I was able to continue running the backend
services using this patched version
  • Loading branch information
MartinquaXD authored Nov 22, 2023
1 parent da717d7 commit bbce7c8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ethcontract-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ethcontract-common"
version = "0.25.3"
version = "0.25.4"
authors = ["Gnosis developers <developers@gnosis.io>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions ethcontract-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ethcontract-derive"
version = "0.25.3"
version = "0.25.4"
authors = ["Gnosis developers <developers@gnosis.io>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -20,8 +20,8 @@ proc-macro = true

[dependencies]
anyhow = "1.0"
ethcontract-common = { version = "0.25.3", path = "../ethcontract-common" }
ethcontract-generate = { version = "0.25.3", path = "../ethcontract-generate", default-features = false }
ethcontract-common = { version = "0.25.4", path = "../ethcontract-common" }
ethcontract-generate = { version = "0.25.4", path = "../ethcontract-generate", default-features = false }
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0"
4 changes: 2 additions & 2 deletions ethcontract-generate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ethcontract-generate"
version = "0.25.3"
version = "0.25.4"
authors = ["Gnosis developers <developers@gnosis.io>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -18,7 +18,7 @@ http = ["curl"]
[dependencies]
anyhow = "1.0"
curl = { version = "0.4", optional = true }
ethcontract-common = { version = "0.25.3", path = "../ethcontract-common" }
ethcontract-common = { version = "0.25.4", path = "../ethcontract-common" }
Inflector = "0.11"
proc-macro2 = "1.0"
quote = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions ethcontract-mock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ethcontract-mock"
version = "0.25.3"
version = "0.25.4"
authors = ["Gnosis developers <developers@gnosis.io>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -12,12 +12,12 @@ Tools for mocking ethereum contracts.
"""

[dependencies]
ethcontract = { version = "0.25.3", path = "../ethcontract", default-features = false, features = ["derive"] }
ethcontract = { version = "0.25.4", path = "../ethcontract", default-features = false, features = ["derive"] }
hex = "0.4"
mockall = "0.11"
rlp = "0.5"
predicates = "3.0"

[dev-dependencies]
tokio = { version = "1.6", features = ["macros", "rt"] }
ethcontract-derive = { version = "0.25.3", path = "../ethcontract-derive", default-features = false }
ethcontract-derive = { version = "0.25.4", path = "../ethcontract-derive", default-features = false }
6 changes: 3 additions & 3 deletions ethcontract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ethcontract"
version = "0.25.3"
version = "0.25.4"
authors = ["Gnosis developers <developers@gnosis.io>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -35,8 +35,8 @@ ws-tokio = ["web3/ws-tokio"]
aws-config = { version = "0.55", optional = true }
aws-sdk-kms = { version = "0.28", optional = true }
arrayvec = "0.7"
ethcontract-common = { version = "0.25.3", path = "../ethcontract-common" }
ethcontract-derive = { version = "0.25.3", path = "../ethcontract-derive", optional = true, default-features = false }
ethcontract-common = { version = "0.25.4", path = "../ethcontract-common" }
ethcontract-derive = { version = "0.25.4", path = "../ethcontract-derive", optional = true, default-features = false }
futures = "0.3"
futures-timer = "3.0"
hex = "0.4"
Expand Down
8 changes: 4 additions & 4 deletions ethcontract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
errors::{DeployError, LinkError},
tokens::Tokenize,
};
use ethcontract_common::abi::{Error as AbiError, Result as AbiResult};
use ethcontract_common::abi::{encode, Error as AbiError, Result as AbiResult};
use ethcontract_common::abiext::FunctionExt;
use ethcontract_common::hash::H32;
use ethcontract_common::{Abi, Bytecode, Contract, DeploymentInformation};
Expand Down Expand Up @@ -202,17 +202,17 @@ impl<T: Transport> Instance<T> {
R: Tokenize,
{
let signature = signature.into().into_inner();
let signature = signature.as_ref();
let function = self
.methods
.get(signature)
.get(&signature)
.map(|(name, index)| &self.abi.functions[name][*index])
.ok_or_else(|| AbiError::InvalidName(hex::encode(signature)))?;
let tokens = match params.into_token() {
ethcontract_common::abi::Token::Tuple(tokens) => tokens,
_ => unreachable!("function arguments are always tuples"),
};
let data = function.encode_input(&tokens)?;

let data = signature.iter().copied().chain(encode(&tokens)).collect();

// take ownership here as it greatly simplifies dealing with futures
// lifetime as it would require the contract Instance to live until
Expand Down

0 comments on commit bbce7c8

Please sign in to comment.