Skip to content

Commit

Permalink
upgrade geth to v1.10.18 to avoid using nightly (privacy-scaling-expl…
Browse files Browse the repository at this point in the history
…orations#540)

* upgrade geth to v1.10.18 to avoid using nightly

* clean

Co-authored-by: DreamWuGit <[email protected]>
  • Loading branch information
lispc and DreamWuGit authored Jun 8, 2022
1 parent a66b76b commit c9e0d42
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 132 deletions.
73 changes: 7 additions & 66 deletions eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,84 +347,25 @@ pub struct ResultGethExecTrace {
pub result: GethExecTrace,
}

#[derive(Deserialize, Debug, Eq, PartialEq)]
#[doc(hidden)]
pub struct GethExecTraceInternal {
pub gas: Gas,
pub failed: bool,
// return_value is a hex encoded byte array
#[serde(rename = "returnValue")]
pub return_value: String,
#[serde(rename = "structLogs")]
pub struct_logs: Vec<GethExecStep>,
}

/// The execution trace type returned by geth RPC debug_trace* methods.
/// Corresponds to `ExecutionResult` in `go-ethereum/internal/ethapi/api.go`.
/// The deserialization truncates the memory of each step in `struct_logs` to
/// the memory size before the expansion, so that it corresponds to the memory
/// before the step is executed.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct GethExecTrace {
/// Used gas
pub gas: Gas,
/// True when the transaction has failed.
pub failed: bool,
/// Return value of execution
/// Return value of execution which is a hex encoded byte array
#[serde(rename = "returnValue")]
pub return_value: String,
/// Vector of geth execution steps of the trace.
#[serde(rename = "structLogs")]
pub struct_logs: Vec<GethExecStep>,
}

/// Truncate the memory in each step to the memory size before the step is
/// executed (and before the memory is expanded). This is required because geth
/// sets the memory in each step as the memory before execution but after
/// expansion.
pub fn fix_geth_trace_memory_size(trace: &mut [GethExecStep]) {
let mut mem_sizes = vec![0; trace.len()];
let mut call_mem_size_stack = Vec::new();
for i in 1..trace.len() {
let step_prev = &trace[i - 1];
let step = &trace[i];
mem_sizes[i] = match step.depth as isize - step_prev.depth as isize {
// Same call context
0 => step_prev.memory.0.len(),
// into new call context
1 => {
call_mem_size_stack.push(step_prev.memory.0.len());
0
}
// return from call context
-1 => call_mem_size_stack.pop().expect("call stack is empty"),
_ => unreachable!(),
};
}
for i in 0..trace.len() {
trace[i].memory.0.truncate(mem_sizes[i]);
}
}

impl<'de> Deserialize<'de> for GethExecTrace {
fn deserialize<D>(deserializer: D) -> Result<GethExecTrace, D::Error>
where
D: serde::Deserializer<'de>,
{
let GethExecTraceInternal {
gas,
failed,
mut struct_logs,
return_value,
} = GethExecTraceInternal::deserialize(deserializer)?;
fix_geth_trace_memory_size(&mut struct_logs);
Ok(Self {
gas,
failed,
struct_logs,
return_value,
})
}
}

#[macro_export]
/// Create an [`Address`] from a hex string. Panics on invalid input.
macro_rules! address {
Expand Down Expand Up @@ -527,11 +468,11 @@ mod tests {
]
}
"#;
let trace: GethExecTraceInternal =
serde_json::from_str(trace_json).expect("json-deserialize GethExecTraceInternal");
let trace: GethExecTrace =
serde_json::from_str(trace_json).expect("json-deserialize GethExecTrace");
assert_eq!(
trace,
GethExecTraceInternal {
GethExecTrace {
gas: Gas(26809),
failed: false,
return_value: "".to_owned(),
Expand Down
2 changes: 1 addition & 1 deletion geth-utils/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module main
go 1.16

require (
github.com/ethereum/go-ethereum v1.10.15
github.com/ethereum/go-ethereum v1.10.18
github.com/holiman/uint256 v1.2.0
)

Expand Down
Loading

0 comments on commit c9e0d42

Please sign in to comment.