Open aMagicNeko opened 6 months ago
It is likely something is not properly initialized around state / host / transaction.
why here m_tx not get value with host.get_tx_context()?
this is my function:
evmc_tx_context SimulateHost::get_tx_context() const noexcept { return _context; }
it's not right to return the evmc_tx_context object without is reference?
It's not right to return the evmc_tx_context object without is reference?
You should return it by reference evmc_tx_context&
. Because otherwise, you will make a temporary copy and later Host will use a reference to this temporary copy what is not ok.
For later, can you send code as text instead of images?
Thanks for remind. However, the base class in evmc_tx_context
.
Ah sorry, you are right. It will keep the copy as m_tx
. So I'm not sure where the problem is exactly.
Can you send a test reproducing your problem?
It's a bit difficult to provide test, because I am using online client to run it.... However, I can provide my code around it. SimulateHost
I don't know. Maybe you want to try address sanitizer or valgrind to provide more debug information?
const evmc_tx_context& get_tx_context() noexcept
{
std::cout << "[get_tx_context] Function called." << std::endl;
std::cout << "this:" << this << std::endl;
if (INTX_UNLIKELY(m_tx.block_timestamp == 0)) {
std::cout << "[get_tx_context] Block timestamp is zero, fetching new tx context." << std::endl;
m_tx = host.get_tx_context();
}
else {
std::cout << "[get_tx_context] Block timestamp is not zero." << std::endl;
}
std::cout << "[get_tx_context] Returning tx context : " << &m_tx << std::endl;
std::cout << "this:" << this << std::endl;
return m_tx;
}
It turnout that this point change to 0x0 after calling m_tx = host.get_tx_context();
why?
The this
object has been deleted?
{
std::cout << "[get_tx_context] Function called." << std::endl;
if (INTX_UNLIKELY(m_tx.block_timestamp == 0)) {
std::cout << "[get_tx_context] Block timestamp is zero, fetching new tx context." << std::endl;
host.get_tx_context();
}
else {
std::cout << "[get_tx_context] Block timestamp is not zero." << std::endl;
}
std::cout << "[get_tx_context] Returning tx context : " << &m_tx << std::endl;
std::cout << "this:" << this << std::endl;
return m_tx;
}
only call the function but not set "m_tx" doesn't make the error
std::cout << "[get_tx_context] Function called." << std::endl;
std::cout << "this:" << this << std::endl;
if (INTX_UNLIKELY(m_tx.block_timestamp == 0)) {
std::cout << "[get_tx_context] Block timestamp is zero, fetching new tx context." << std::endl;
auto tmp = host.get_tx_context();
m_tx = tmp;
}
else {
std::cout << "[get_tx_context] Block timestamp is not zero." << std::endl;
}
std::cout << "[get_tx_context] Returning tx context : " << &m_tx << std::endl;
std::cout << "this:" << this << std::endl;
return m_tx;
}
```however, give the tmp variant the return value, the stack would be destroyed.
When I compile with -O0, no crash happens.... Maybe the bug of compiler...
@chfast Hi, brother. I change the return value of the function get_tx_context
to const evmc_tx_context *
and it performs well. Should I push it?
I am running on ubuntu arm, please help me.