Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ed7b1ba
Add `erigon_getHeaderByNumber`
JamesHinshelwood Apr 24, 2023
5722467
Add `ots_getApiLevel`
JamesHinshelwood Apr 24, 2023
3859541
Add `ots_hasCode`
JamesHinshelwood Apr 24, 2023
9223ace
Add `ots_getBlockDetails`
JamesHinshelwood Apr 24, 2023
33ca374
Add `ots_getBlockTransactions`
JamesHinshelwood Apr 24, 2023
4e9e359
Add `ots_getContractCreator`
JamesHinshelwood Apr 24, 2023
101846e
Merge branch 'otterscan' into otter
n-hutton May 16, 2023
6523035
WIP
n-hutton May 18, 2023
9236492
WIP, first pass
n-hutton May 23, 2023
68d8f66
adhere to otter pagination
n-hutton May 23, 2023
65e6ed0
more cleanup
n-hutton May 23, 2023
60d21df
add the otter tests too
n-hutton May 23, 2023
0f51026
further cleanup
n-hutton May 23, 2023
6ca45e3
hmm
n-hutton May 24, 2023
087413b
Merge branch 'master' into otter
n-hutton May 24, 2023
c4893d3
cleanup
n-hutton May 24, 2023
ab7f98a
more fixes
n-hutton May 24, 2023
6a7eb86
add before figuring out why ci fails
n-hutton May 24, 2023
929029a
add before figuring out why ci fails2
n-hutton May 24, 2023
30851ce
back to it..
n-hutton May 24, 2023
8fcc60d
disable otter test...
n-hutton May 24, 2023
4836ae4
remove debug
n-hutton May 24, 2023
5012731
make mocha work better hopefully
n-hutton May 24, 2023
6469aed
increase timeout...
n-hutton May 24, 2023
6cc24be
readd batch transfer
n-hutton May 24, 2023
31ede36
clean
n-hutton May 24, 2023
1864f2f
bail on first test failure
n-hutton May 24, 2023
4eb997d
hope it wasn't this...
n-hutton May 24, 2023
1e6e02f
getting desperate..
n-hutton May 24, 2023
1058cea
hard kill
n-hutton May 24, 2023
6fc381a
make it an interrupt
n-hutton May 24, 2023
d47d12a
cleanup
n-hutton May 25, 2023
1fa9076
Update evm-ds/src/evm_server_run.rs
n-hutton May 25, 2023
339f80c
cleanup
n-hutton May 25, 2023
40c669c
asdfsdf
n-hutton May 25, 2023
0a41d1f
sigh
n-hutton May 25, 2023
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
8 changes: 4 additions & 4 deletions evm-ds/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion evm-ds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bytes = "1.1.0"
clap = { version = "3.1.6", features = ["derive"] }
log4rs = { version = "1.1.1", features = ["all_components", "gzip"] }
ethereum = "0.12.0"
evm = { git = "https://github.com/Zilliqa/evm", branch = "precompile-access-backend", features = ["tracing"] }
evm = { git = "https://github.com/Zilliqa/evm", branch = "precompile-backend-plus-otter", features = ["tracing"] }
ethabi = "18.0.0"
serde = "1.0.152"
serde_yaml = "0.8.25"
Expand Down
8 changes: 8 additions & 0 deletions evm-ds/src/cps_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ impl<'a> Handler for CpsExecutor<'a> {
}
}

fn get_create_address(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

now a requirement of handler via the evm PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is get_create_address actually used anywhere in this PR? I can't find any usages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the other PR that adds evm functionality it adds it as a handler fn and is used there impl<'a> Handler for CpsExecutor<'a>

&mut self,
scheme: CreateScheme,
) -> H160 {
self.stack_executor.create_address(scheme)
}


/// Invoke a call operation.
fn call(
&mut self,
Expand Down
20 changes: 12 additions & 8 deletions evm-ds/src/evm_server_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use std::sync::{Arc, Mutex};

use crate::CallContext;
use evm::executor::stack::MemoryStackSubstate;
use evm::{
backend::Apply,
executor::stack::{MemoryStackState, StackSubstateMetadata},
};
use evm::{backend::Apply, executor::stack::{MemoryStackState, StackSubstateMetadata}};
use evm::{Machine, Runtime};

use log::{debug, error, info};
Expand Down Expand Up @@ -50,9 +47,9 @@ pub async fn run_evm_impl(
// panic. (Using the parent runtime and dropping on stack unwind will mess up the parent runtime).
tokio::task::spawn_blocking(move || {
debug!(
"Running EVM: origin: {:?} address: {:?} gas: {:?} value: {:?} extras: {:?}, estimate: {:?}, cps: {:?}, tx_trace: {:?}",
"Running EVM: origin: {:?} address: {:?} gas: {:?} value: {:?} extras: {:?}, estimate: {:?} is_continuation: {:?}, cps: {:?}, \ntx_trace: {:?}, \ndata: {:02X?}, \ncode: {:02X?}",
backend.origin, address, gas_limit, apparent_value,
backend.extras, estimate, enable_cps, tx_trace);
backend.extras, estimate, node_continuation.is_none(), enable_cps, tx_trace, data, code);
let code = Rc::new(code);
let data = Rc::new(data);
// TODO: handle call_l64_after_gas problem: https://zilliqa-jira.atlassian.net/browse/ZIL-5012
Expand Down Expand Up @@ -157,25 +154,31 @@ pub async fn run_evm_impl(
listener.finished_call();

match exit_reason {
evm::ExitReason::Succeed(_) => {}
evm::ExitReason::Revert(_) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

when tx fails, capture error blob

listener.otter_transaction_error = format!("0x{}", hex::encode(runtime.machine().return_value()));
}
_ => {
debug!("Machine: position: {:?}, memory: {:?}, stack: {:?}",
runtime.machine().position(),
&runtime.machine().memory().data().iter().take(128).collect::<Vec<_>>(),
&runtime.machine().stack().data().iter().take(128).collect::<Vec<_>>());
}
}

build_exit_result(executor, &runtime, &backend, &listener, &exit_reason, remaining_gas, is_static, continuations)
},
CpsReason::CallInterrupt(i) => {
let cont_id = continuations.lock().unwrap().create_continuation(runtime.machine_mut(), executor.state().substate());

build_call_result(executor, &runtime, &backend, i, &listener, remaining_gas, is_static, cont_id)
},
CpsReason::CreateInterrupt(i) => {
let cont_id = continuations.lock().unwrap().create_continuation(runtime.machine_mut(), executor.into_state().substate());

build_create_result(&runtime, i, &listener, remaining_gas, cont_id)
}
};

info!(
"EVM execution summary: context: {:?}, origin: {:?} address: {:?} gas: {:?} value: {:?}, data: {:?}, extras: {:?}, estimate: {:?}, cps: {:?}, result: {}, returnVal: {}",
evm_context, backend.origin, address, gas_limit, apparent_value,
Expand Down Expand Up @@ -322,6 +325,7 @@ fn build_call_result(
context.set_apparent_value(interrupt.context.apparent_value.into());
context.set_caller(interrupt.context.caller.into());
context.set_destination(interrupt.context.address.into());

trap_data_call.set_context(context);

if let Some(tran) = interrupt.transfer {
Expand Down Expand Up @@ -414,4 +418,4 @@ fn handle_panic(trace: String, remaining_gas: u64, reason: &str) -> EvmProto::Ev
result.set_tx_trace(trace.into());
result.set_remaining_gas(remaining_gas);
result
}
}
117 changes: 116 additions & 1 deletion evm-ds/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ struct Args {
zil_scaling_factor: u64,
}

#[derive(Debug, Serialize, Deserialize, Default)]
struct OtterscanCallContext {
#[serde(rename = "type")]
pub call_type: String,
pub depth: usize,
pub from: String,
pub to: String,
pub value: String,
pub input: String,
}

#[derive(Debug, Serialize, Deserialize, Default)]
struct CallContext {
#[serde(rename = "type")]
Expand Down Expand Up @@ -114,6 +125,10 @@ struct StructLog {
struct LoggingEventListener {
call_tracer: Vec<CallContext>,
raw_tracer: StructLogTopLevel,
otter_internal_tracer: Vec<InternalOperationOtter>,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reuse transaction trace struct

otter_call_tracer: Vec<OtterscanCallContext>,
otter_transaction_error: String,
otter_addresses_called: Vec<String>,
enabled: bool,
}

Expand All @@ -126,11 +141,24 @@ struct StructLogTopLevel {
pub struct_logs: Vec<StructLog>,
}

#[derive(Debug, Serialize, Deserialize, Default)]
struct InternalOperationOtter {
#[serde(rename = "type")]
pub call_type: usize,
pub from: String,
pub to: String,
pub value: String,
}

impl LoggingEventListener {
fn new(enabled: bool) -> Self {
LoggingEventListener {
call_tracer: Default::default(),
raw_tracer: Default::default(),
otter_internal_tracer: Default::default(),
otter_call_tracer: Default::default(),
otter_transaction_error: "0x".to_string(),
otter_addresses_called: Default::default(),
enabled,
}
}
Expand All @@ -142,11 +170,15 @@ impl evm::runtime::tracing::EventListener for LoggingEventListener {
return;
}

let call_depth = self.call_tracer.len() - 1;

let mut struct_log = StructLog {
depth: self.call_tracer.len() - 1,
depth: call_depth,
..Default::default()
};

let mut intern_trace = None;

match event {
evm::runtime::tracing::Event::Step {
context: _,
Expand Down Expand Up @@ -183,11 +215,94 @@ impl evm::runtime::tracing::EventListener for LoggingEventListener {
} => {
struct_log.op = "SStore".to_string();
}
evm::runtime::tracing::Event::TransactTransfer {
call_type,
address,
target,
balance,
input,
} => {
intern_trace = Some(InternalOperationOtter {
call_type: call_depth,
from: format!("{:?}", address),
to: format!("{:?}", target),
value: format!("{:0X?}", balance),
});

self.otter_call_tracer.push(OtterscanCallContext{
call_type: call_type.to_string(),
depth: call_depth,
from: format!("{:?}", address),
to: format!("{:?}", target),
value: format!("{:0X?}", balance),
input: input.to_string(),});

let to_add = format!("{:?}", target);

// only push if doesn't exist in otter_addresses_called
if !self.otter_addresses_called.contains(&to_add) {
self.otter_addresses_called.push(to_add);
}
}
evm::runtime::tracing::Event::TransactSuicide {
address,
target,
balance,
} => {
intern_trace = Some(InternalOperationOtter {
call_type: 1,
from: format!("{:?}", address),
to: format!("{:?}", target),
value: format!("{:0X?}", balance),
});

self.otter_call_tracer.push(OtterscanCallContext{
call_type: "SELFDESTRUCT".to_string(),
depth: call_depth,
from: format!("{:?}", address),
to: format!("{:?}", target),
value: format!("{:0X?}", balance),
input: "".to_string(),});
}
evm::runtime::tracing::Event::TransactCreate {
call_type,
address,
target,
balance,
is_create2,
input,
} => {
intern_trace = Some(InternalOperationOtter {
call_type: if is_create2 { 3 } else { 2 },
from: format!("{:?}", address),
to: format!("{:?}", target),
value: format!("{:0X?}", balance),
});

self.otter_call_tracer.push(OtterscanCallContext{
call_type: call_type.to_string(),
depth: call_depth,
from: format!("{:?}", address),
to: format!("{:?}", target),
value: format!("{:0X?}", balance),
input: input.to_string(),});

let to_add = format!("{:?}", target);

// only push if doesn't exist in otter_addresses_called
if !self.otter_addresses_called.contains(&to_add) {
self.otter_addresses_called.push(to_add);
}
}
}

if self.raw_tracer.struct_logs.len() < 5 {
self.raw_tracer.struct_logs.push(struct_log);
}

if let Some(intern_trace) = intern_trace {
self.otter_internal_tracer.push(intern_trace);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion scripts/integration_test_js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ else

cd tests/EvmAcceptanceTests/
npm install
DEBUG=true MOCHA_TIMEOUT=20000 npx hardhat test
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this has effect of not interleaving the hardhat output with the iso server output, it just dumps it after

DEBUG=true MOCHA_TIMEOUT=40000 npx hardhat test --bail 2>&1 > npx.out

retVal=$?

pkill -INT isolatedServer
cat npx.out
if [ $retVal -ne 0 ]; then
echo "!!!!!! Error with JS integration test !!!!!!"
exit 1
Expand Down
4 changes: 4 additions & 0 deletions src/libCps/CpsRunEvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "libEth/utils/EthUtils.h"
#include "libMetrics/Api.h"
#include "libMetrics/Tracing.h"
#include "libPersistence/BlockStorage.h"
#include "libUtils/DataConversion.h"
#include "libUtils/EvmUtils.h"
#include "libUtils/GasConv.h"
Expand Down Expand Up @@ -75,6 +76,9 @@ CpsExecuteResult CpsRunEvm::Run(TransactionReceipt& receipt) {
TRACE_ERROR("Insufficient Balance");
return {TxnStatus::INSUFFICIENT_BALANCE, false, {}};
}
if (!BlockStorage::GetBlockStorage().PutContractCreator(contractAddress, mCpsContext.scillaExtras.txnHash)) {
LOG_GENERAL(WARNING, "Failed to save contract creator");
}
// Contract call (non-trap)
} else if (GetType() == CpsRun::Call) {
INC_STATUS(GetCPSMetric(), "transaction", "call");
Expand Down
5 changes: 5 additions & 0 deletions src/libCps/CpsRunScilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "libCps/ScillaHelpersCall.h"
#include "libCps/ScillaHelpersCreate.h"
#include "libData/AccountData/TransactionReceipt.h"
#include "libPersistence/BlockStorage.h"
#include "libScilla/ScillaClient.h"
#include "libScilla/ScillaUtils.h"
#include "libUtils/DataConversion.h"
Expand Down Expand Up @@ -224,6 +225,10 @@ CpsExecuteResult CpsRunScilla::runCreate(TransactionReceipt& receipt) {
mAccountStore.AddAddressToUpdateBufferAtomic(mArgs.from);
mAccountStore.AddAddressToUpdateBufferAtomic(mArgs.dest);

if (!BlockStorage::GetBlockStorage().PutContractCreator(mArgs.dest, mCpsContext.scillaExtras.txnHash)) {
LOG_GENERAL(WARNING, "Failed to save contract creator");
}

return {TxnStatus::NOT_PRESENT, true, ScillaResult{mArgs.gasLimit}};
}

Expand Down
3 changes: 2 additions & 1 deletion src/libCps/CpsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ ScillaProcessContext CpsUtils::FromEvmContext(
.blockDifficulty = 0,
// Not relevant
.contractType = Transaction::ContractType::ERROR,
.txnHash = evmContext.GetTranID()
};
}

} // namespace libCps
} // namespace libCps
24 changes: 23 additions & 1 deletion src/libData/AccountStore/AccountStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,30 @@ bool AccountStore::UpdateAccountsTemp(
<< transaction.GetTranID() << "> ("
<< (status ? "Successfully)" : "Failed)"));

// Record and publish delay
// This needs to be outside the above as needs to include possibility of non evm tx
if(ARCHIVAL_LOOKUP_WITH_TX_TRACES) {

if (!BlockStorage::GetBlockStorage().PutOtterAddressNonceLookup(transaction.GetTranID(),
transaction.GetNonce() - 1, transaction.GetSenderAddr().hex())) {
LOG_GENERAL(INFO,
"FAIL: Put otter addr mapping failed " << transaction.GetTranID());
}

// For when vanilla TX, we still want to log this for otterscan
if (!isEvm) {
std::set<std::string> addresses_touched;
addresses_touched.insert(transaction.GetSenderAddr().hex());
addresses_touched.insert(transaction.GetToAddr().hex());

if (!BlockStorage::GetBlockStorage().PutOtterTxAddressMapping(transaction.GetTranID(),
addresses_touched, blockNum)) {
LOG_GENERAL(INFO,
"FAIL: Put otter addr mapping failed " << transaction.GetTranID());
}
}
}

// Record and publish delay
auto delay = r_timer_end(tpLatencyStart);
double dVal = delay / 1000;
if (dVal > 0) {
Expand Down
Loading