Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5e1b135
Add more evm methods support
sudo-shashank Aug 12, 2025
675ea95
Add test snapshots
sudo-shashank Aug 12, 2025
9f61a31
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 12, 2025
615985f
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 13, 2025
c5bd5c2
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 13, 2025
a4dfff2
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 13, 2025
6b503b6
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 13, 2025
0ddf9d9
fmt
sudo-shashank Aug 13, 2025
c42b6f3
fmt
sudo-shashank Aug 13, 2025
c984a48
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 14, 2025
b105cfc
Use serde
sudo-shashank Aug 14, 2025
a2c016d
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 14, 2025
ce06d41
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 18, 2025
b8be085
add GetStorageAt
sudo-shashank Aug 19, 2025
61a2860
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 19, 2025
b14e1d5
lint fix
sudo-shashank Aug 19, 2025
0a5bf32
fix error msg
sudo-shashank Aug 19, 2025
318fd27
fix
sudo-shashank Aug 20, 2025
13a687f
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 20, 2025
89d1ad4
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 21, 2025
ca4a825
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 21, 2025
529531a
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 25, 2025
fe0cb6a
minor fix
sudo-shashank Aug 25, 2025
20e52b4
use ensure
sudo-shashank Aug 25, 2025
f37dca4
Merge branch 'main' into shashank/evm-state-decode-params
sudo-shashank Aug 25, 2025
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
158 changes: 158 additions & 0 deletions src/lotus_json/actor_states/methods/evm_actor_params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Copyright 2019-2025 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT
use super::*;
use crate::rpc::eth::types::GetStorageAtParams;
use crate::shim::econ::TokenAmount;
use ::cid::Cid;
use fvm_ipld_encoding::RawBytes;
use paste::paste;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct EVMConstructorParamsLotusJson {
pub creator: [u8; 20],
#[schemars(with = "LotusJson<RawBytes>")]
#[serde(with = "crate::lotus_json")]
pub initcode: RawBytes,
}

macro_rules! impl_evm_constructor_params {
($($version:literal),+) => {
$(
paste! {
impl HasLotusJson for fil_actor_evm_state::[<v $version>]::ConstructorParams {
type LotusJson = EVMConstructorParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![
(
json!({
"Creator": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
"Initcode": "ESIzRFU="
}),
Self {
creator: fil_actor_evm_state::evm_shared::[<v $version>]::address::EthAddress([0; 20]),
initcode: RawBytes::new(hex::decode("1122334455").unwrap()),
},
),
]
}

fn into_lotus_json(self) -> Self::LotusJson {
EVMConstructorParamsLotusJson {
creator: self.creator.0,
initcode: self.initcode,
}
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
creator: fil_actor_evm_state::evm_shared::[<v $version>]::address::EthAddress(lotus_json.creator),
initcode: lotus_json.initcode,
}
}
}
}
)+
};
}

impl_evm_constructor_params!(10, 11, 12, 13, 14, 15, 16);

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct EVMDelegateCallParamsLotusJson {
#[schemars(with = "LotusJson<Cid>")]
#[serde(with = "crate::lotus_json")]
pub code: Cid,
#[schemars(with = "LotusJson<RawBytes>")]
#[serde(with = "crate::lotus_json")]
pub input: RawBytes,
pub caller: [u8; 20],
#[schemars(with = "LotusJson<TokenAmount>")]
#[serde(with = "crate::lotus_json")]
pub value: TokenAmount,
}

macro_rules! impl_evm_delegate_call_params_lotus_json {
($($version:literal),+) => {
$(
paste! {
impl HasLotusJson for fil_actor_evm_state::[<v $version>]::DelegateCallParams {
type LotusJson = EVMDelegateCallParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({
"Code": "bafy2bzaceaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"Input": "ESIzRFU=",
"Caller": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
"Value": "0"
}),
Self {
code: Cid::default(),
input: hex::decode("1122334455").unwrap(),
caller: fil_actor_evm_state::evm_shared::[<v $version>]::address::EthAddress([0; 20]),
value: TokenAmount::from_atto(0).into(),
},
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
EVMDelegateCallParamsLotusJson {
code: self.code,
input: self.input.into(),
caller: self.caller.0,
value: self.value.into(),
}
}
fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Self {
code: lotus_json.code,
input: lotus_json.input.into(),
caller: fil_actor_evm_state::evm_shared::[<v $version>]::address::EthAddress(lotus_json.caller),
value: lotus_json.value.into(),
}
}
}}
)+
};
}

impl_evm_delegate_call_params_lotus_json!(10, 11, 12, 13, 14, 15, 16);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct GetStorageAtParamsLotusJson {
pub storage_key: [u8; 32],
}

impl HasLotusJson for GetStorageAtParams {
type LotusJson = GetStorageAtParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(
json!({
"StorageKey": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]
}),
GetStorageAtParams::new(vec![0xa]).unwrap(),
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
GetStorageAtParamsLotusJson {
storage_key: self.0,
}
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
GetStorageAtParams::new(lotus_json.storage_key.to_vec())
.expect("expected array to have 32 elements")
}
}
62 changes: 0 additions & 62 deletions src/lotus_json/actor_states/methods/evm_constructor_params.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/lotus_json/actor_states/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod account_authenticate_params;
mod account_constructor_params;
mod cron_actor_params;
mod datacap_actor_params;
mod evm_constructor_params;
mod evm_actor_params;
mod init_constructor_params;
mod init_exec4_params;
mod init_exec_params;
Expand Down
18 changes: 14 additions & 4 deletions src/rpc/methods/eth/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ impl FromStr for EthBytes {
pub struct GetBytecodeReturn(pub Option<Cid>);

const GET_STORAGE_AT_PARAMS_ARRAY_LENGTH: usize = 32;
const LENGTH_BUF_GET_STORAGE_AT_PARAMS: u8 = 129;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct GetStorageAtParams(pub [u8; GET_STORAGE_AT_PARAMS_ARRAY_LENGTH]);

impl GetStorageAtParams {
Expand All @@ -80,11 +81,20 @@ impl GetStorageAtParams {
}

pub fn serialize_params(&self) -> anyhow::Result<Vec<u8>> {
const LENGTH_BUF_GET_STORAGE_AT_PARAMS: u8 = 129;
let mut encoded = fvm_ipld_encoding::to_vec(&RawBytes::new(self.0.to_vec()))?;
encoded.insert(0, LENGTH_BUF_GET_STORAGE_AT_PARAMS);
let mut encoded = vec![LENGTH_BUF_GET_STORAGE_AT_PARAMS];
fvm_ipld_encoding::to_writer(&mut encoded, &RawBytes::new(self.0.to_vec()))?;
Ok(encoded)
}

pub fn deserialize_params(bz: &[u8]) -> anyhow::Result<Self> {
let (&prefix, bytes) = bz.split_first().context("unexpected EOF")?;
ensure!(
prefix == LENGTH_BUF_GET_STORAGE_AT_PARAMS,
"expected CBOR array of length 1"
);
let decoded: RawBytes = fvm_ipld_encoding::from_slice(bytes)?;
GetStorageAtParams::new(decoded.into())
}
}

#[derive(
Expand Down
26 changes: 24 additions & 2 deletions src/rpc/registry/actors/evm.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
// Copyright 2019-2025 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::rpc::eth::types::GetStorageAtParams;
use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods};
use crate::shim::message::MethodNum;
use cid::Cid;
use fvm_ipld_encoding::RawBytes;

macro_rules! register_evm_version {
($registry:expr, $code_cid:expr, $state_version:path) => {{
use $state_version::{ConstructorParams, Method};
use $state_version::{ConstructorParams, DelegateCallParams, Method};

register_actor_methods!(
$registry,
$code_cid,
[(Method::Constructor, ConstructorParams)]
[
(Method::Constructor, ConstructorParams),
(Method::Resurrect, ConstructorParams),
(Method::InvokeContract, RawBytes),
(Method::InvokeContractDelegate, DelegateCallParams),
]
);

$registry.register_method(
$code_cid,
Method::GetStorageAt as MethodNum,
GetStorageAtParams::deserialize_params,
);

register_actor_methods!(
$registry,
$code_cid,
[
(Method::GetBytecode, empty),
(Method::GetBytecodeHash, empty)
]
);
}};
}
Expand Down
Loading
Loading