ethereum / evmone

Fast Ethereum Virtual Machine implementation
Apache License 2.0
847 stars 283 forks source link

why evmone crash when invoke? #868

Open aMagicNeko opened 6 months ago

aMagicNeko commented 6 months ago

I am running on ubuntu arm, please help me. image image

chfast commented 6 months ago

It is likely something is not properly initialized around state / host / transaction.

aMagicNeko commented 6 months ago

image 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?

chfast commented 6 months ago

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?

aMagicNeko commented 6 months ago

Thanks for remind. However, the base class in require that the return type must be evmc_tx_context.

chfast commented 6 months ago

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?

aMagicNeko commented 6 months ago

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

chfast commented 6 months ago

I don't know. Maybe you want to try address sanitizer or valgrind to provide more debug information?

aMagicNeko commented 6 months ago
 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?

chfast commented 6 months ago

The this object has been deleted?

aMagicNeko commented 6 months ago
    {
        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.
aMagicNeko commented 6 months ago

When I compile with -O0, no crash happens.... Maybe the bug of compiler...

aMagicNeko commented 6 months ago

@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?