mit-dci / opencbdc-tx

A transaction processor for a hypothetical, general-purpose, central bank digital currency
Other
895 stars 200 forks source link

[EVM] Ifinite Loop #216

Closed hellgate13 closed 1 year ago

hellgate13 commented 1 year ago

Affected Branch

programmability

Basic Diagnostics

Description

In order to reproduce the issue, follow these steps:

  1. Create a smart contract that only issues for testing purposes.
  2. Deploy it using hardhat
  3. Update Contract Address, Run Web3JS function
  4. Infinite Loop

For now, based on the logs, it looks like the write locked and not released. do_try_lock_request of type write when m_is_readonly_run = true

The tested logs can be found in the following repositories : https://github.com/Black-NS/opencbdc-erc20-tesing/tree/develop/logs

NOTE : The logs can be updated by testing again.

NOTE : I've seen it behave normally when run via metamask or hardhat because input data into the sendRawTransaction and executing it worked fine. This was the same when I created the Raw Transaction with data.

Thank you.

Code of Conduct

anders94 commented 1 year ago

@metalicjames

AlexRamRam commented 1 year ago

Thanks for your report @hellgate13. It's worth pointing out that the server's response to methods.mint.call(...) (which invokes ethereum's eth_call json_rpc) is not well-defined since the mint() call requires an alteration to the contract's state. The system does handle functions that can be run locally (i.e. read-only) without changing state such as: myContract.methods.totalSupply().call().then(console.log).

All of that being said, the system's response is certainly not correct and it should not crash. We will issue a fix in the next few days.

hellgate13 commented 1 year ago

Thank you for Response.

However I do have one question.

I think that executing a smart contract by putting ABI code in the input data to sendRawTransxaction also has the commonality of changing the contract state like using eth_call.

{
  ...
  from: '0x01A151CC5ED14d110cc0e6b64360913DE9f453F1',
  to: '0x01A151CC5ED14d110cc0e6b64360913DE9f453F1',
  value: BigNumber { value: "0" },
  data: '0xa0712d6800000000000000000000000000000000000000000000000000000000000003e8', <- this
  ...
}

Arccrding to your answer, System only handles read-only functions, so I think the ABI Byte code in sendRawTransaction shouldn;t have been executed.

I realize i'm asking a dumb question because I don't understand System Architecture, but maybe you can help me out?

AlexRamRam commented 1 year ago

The system, of course, handles transactions that modify state.

The mint() function of your contract - which requires a change to the state of contract - can be invoked with both eth_sendRawTransaction and eth_call. However, as described in the Ethereum JSON-RPC API, eth_call must execute messages "without creating a transaction on the block chain" and hence the system behavior when invoked with a state changing function is not well defined. Note that eth_sendRawTransaction does indeed commit state changes.

Also, note the web3js documentation you linked above on methods.myMethod.call: "Will call a “constant” method and execute its smart contract method in the EVM without sending any transaction. Note calling cannot alter the smart contract state."

I hope I understood your question correctly and you find this helpful.

Again, we will make changes such that the system responds gracefully when eth_call is invoked with a function that requires state changes.

hellgate13 commented 1 year ago

thank you for your answering my stupid question.

it made me realize that i need to study much more about blockchain system, Web3JS and OpenCBDC System.

AlexRamRam commented 1 year ago

thank you for your answering my stupid question.

it made me realize that i need to study much more about blockchain system, Web3JS and OpenCBDC System.

Not at all @hellgate13. Your contribution is appreciated and we look forward to hearing more of your work.

maurermi commented 1 year ago

Sounds like this issue has been resolved. Additionally, the referenced commit by @AlexRamRam resolves the infinite loop problem if call() is used in an attempt to change state. @hellgate13 are you comfortable with this issue being closed?

hellgate13 commented 1 year ago

thank you for update.

The contract.mint.send(from : address) in web3j library is throwing a signature error, but i'm guessing this is a problem with my setup.

I have checked that when i incorrectly request the mint function with call ( contract.mint.call() ) it returns an empty value.

I agree that this issue is closed.