Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why evmone crash when invoke? #868

Open
aMagicNeko opened this issue Apr 17, 2024 · 12 comments
Open

why evmone crash when invoke? #868

aMagicNeko opened this issue Apr 17, 2024 · 12 comments

Comments

@aMagicNeko
Copy link

aMagicNeko commented Apr 17, 2024

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

@chfast
Copy link
Member

chfast commented Apr 17, 2024

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

@aMagicNeko
Copy link
Author

aMagicNeko commented Apr 17, 2024

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
Copy link
Member

chfast commented Apr 17, 2024

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
Copy link
Author

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

@chfast
Copy link
Member

chfast commented Apr 17, 2024

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
Copy link
Author

aMagicNeko commented Apr 17, 2024

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
Copy link
Member

chfast commented Apr 17, 2024

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

@aMagicNeko
Copy link
Author

aMagicNeko commented Apr 17, 2024

 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
Copy link
Member

chfast commented Apr 17, 2024

The this object has been deleted?

@aMagicNeko
Copy link
Author

   {
       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
Copy link
Author

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

@aMagicNeko
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants