Skip to content

Commit f65f619

Browse files
authored
feat: take calldata in Precompile::signature (#12354)
The current abstraction assumes that precompiles are pure functions and ABI-incompatible. However, some precompiles may require additional data from the calldata to determine their signature, for example precompiles that are actually full contracts with multiple functions.
1 parent 0f5eff2 commit f65f619

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

crates/evm/traces/src/decoder/precompiles.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(super) fn decode(trace: &CallTrace, _chain_id: u64) -> Option<DecodedCallTra
6262

6363
for &precompile in PRECOMPILES {
6464
if trace.address == precompile.address() {
65-
let signature = precompile.signature();
65+
let signature = precompile.signature(&trace.data);
6666

6767
let args = precompile
6868
.decode_call(&trace.data)
@@ -90,7 +90,7 @@ pub(super) fn decode(trace: &CallTrace, _chain_id: u64) -> Option<DecodedCallTra
9090

9191
pub(super) trait Precompile {
9292
fn address(&self) -> Address;
93-
fn signature(&self) -> &'static str;
93+
fn signature(&self, data: &[u8]) -> &'static str;
9494

9595
fn decode_call(&self, data: &[u8]) -> alloy_sol_types::Result<Vec<String>> {
9696
Ok(vec![hex::encode_prefixed(data)])
@@ -123,7 +123,7 @@ impl Precompile for Ecrecover {
123123
EC_RECOVER
124124
}
125125

126-
fn signature(&self) -> &'static str {
126+
fn signature(&self, _: &[u8]) -> &'static str {
127127
ecrecoverCall::SIGNATURE
128128
}
129129

@@ -144,7 +144,7 @@ impl Precompile for Sha256 {
144144
SHA_256
145145
}
146146

147-
fn signature(&self) -> &'static str {
147+
fn signature(&self, _: &[u8]) -> &'static str {
148148
sha256Call::SIGNATURE
149149
}
150150

@@ -160,7 +160,7 @@ impl Precompile for Ripemd160 {
160160
RIPEMD_160
161161
}
162162

163-
fn signature(&self) -> &'static str {
163+
fn signature(&self, _: &[u8]) -> &'static str {
164164
ripemdCall::SIGNATURE
165165
}
166166

@@ -176,7 +176,7 @@ impl Precompile for Identity {
176176
IDENTITY
177177
}
178178

179-
fn signature(&self) -> &'static str {
179+
fn signature(&self, _: &[u8]) -> &'static str {
180180
identityCall::SIGNATURE
181181
}
182182
}
@@ -187,7 +187,7 @@ impl Precompile for ModExp {
187187
MOD_EXP
188188
}
189189

190-
fn signature(&self) -> &'static str {
190+
fn signature(&self, _: &[u8]) -> &'static str {
191191
modexpCall::SIGNATURE
192192
}
193193

@@ -216,7 +216,7 @@ impl Precompile for EcAdd {
216216
EC_ADD
217217
}
218218

219-
fn signature(&self) -> &'static str {
219+
fn signature(&self, _: &[u8]) -> &'static str {
220220
ecaddCall::SIGNATURE
221221
}
222222

@@ -237,7 +237,7 @@ impl Precompile for Ecmul {
237237
EC_MUL
238238
}
239239

240-
fn signature(&self) -> &'static str {
240+
fn signature(&self, _: &[u8]) -> &'static str {
241241
ecmulCall::SIGNATURE
242242
}
243243

@@ -258,7 +258,7 @@ impl Precompile for Ecpairing {
258258
EC_PAIRING
259259
}
260260

261-
fn signature(&self) -> &'static str {
261+
fn signature(&self, _: &[u8]) -> &'static str {
262262
ecpairingCall::SIGNATURE
263263
}
264264

@@ -288,7 +288,7 @@ impl Precompile for Blake2f {
288288
BLAKE_2F
289289
}
290290

291-
fn signature(&self) -> &'static str {
291+
fn signature(&self, _: &[u8]) -> &'static str {
292292
blake2fCall::SIGNATURE
293293
}
294294

@@ -321,7 +321,7 @@ impl Precompile for PointEvaluation {
321321
POINT_EVALUATION
322322
}
323323

324-
fn signature(&self) -> &'static str {
324+
fn signature(&self, _: &[u8]) -> &'static str {
325325
pointEvaluationCall::SIGNATURE
326326
}
327327

0 commit comments

Comments
 (0)