Can Ethereum transaction (calling contract function) fail for reasons other than assert()/require()/revert() or gas issues? - exception

When running a private Ethereum network not requiring gas for transactions, can a contract function transaction fail for some "unpredictable" issue, other than explicit invocation of assert()/require()/revert(), for example dividing by 0 or some other issue with EVM or beyond EVM?

division by zero
integer overflow/underflow in Solidity 0.8+ (previous versions let the number overflow, 0.8 throws an exception)
accessing out-of-bounds array index
message call (aka internal transaction) to an address that does not implement the called function (might have been selfdestruct or changed implementation behind a proxy)
These I could think of right now. I'm sure there's more examples, generally runtime errors cause by some logical mistake.

Related

How many EVM in Ethereum chain?

I am really confused for now. I am working on Solidity DEV, but today, I try to think of one question, how many EVM is in the Ethereum chain?
I am not joking. I really want to know, when to create the EVM. I have read the doc https://ethereum.org/en/developers/docs/evm/. But still not clear about that question. So, I mean, whether we only have one EVM in the chain or each validation node(RPC node) has one EVM or when the metamask tries to make a transaction with the RPC node, the RPC node creates an EVM and loads the target smart contract or each metamask is an EVM. I am really confused now. Please help me, if you know the sure answer. Really really thanks.
EVM is smart contract runtime. Each ethereum node has Ethereum software and inside the software, it is running a virtual computer. EVM is a Turing-complete machine and since it runs on different nodes and you have no access to it, it is called a "virtual machine". It is a kinda cloud computing machine. the only thing this machine can do is execute smart contracts.
Metamask is just a wallet, a middleman. It passes your requests to Ethereum blockchain.

Is part of the miner work to schedulle some smart contract executions?

I'm just trying to start to learn about ethereum and smart contracts and I'm understanding that the execution of an smart contract happens during the process of a transaction block's validation. Am I right about it?
If so, how is executed smart contracts that have an expiration date or some sort of execution that have to happen in the future? Is part of the miner work to schedulle some smart contracts executions?
the execution of an smart contract happens during the process of a transaction block's validation
As well as during the block mining. But yes, PoW validators run the transaction too - only this time with params (such as block.timestamp) of the block being validated to check if they get the same result (in this context state changes - storage, events, ...) as the miner.
Example:
function foo() public {
require(block.timestamp == 1650000000);
}
A miner produces a block with timestamp 1650000000, includes a transaction that successfully executes the foo() function.
A validator validates this block at time 1650000001 but executes it in their EVM with simulated time 1650000000, and the transaction succeeds on their end as well.

Is this a clean way to withdraw from a contract in Solidity?

I have been looking high and low about how to withdraw the funds from an Ethereum contract with no prevail. The Remix editor is giving the warning that this function may cause an infinite loop.
Gas requirement of function KOTH.cleanTheKingsChest() high: infinite. If the gas requirement of a function is higher than the block gas limit, it cannot be executed. Please avoid loops in your functions or actions that modify large areas of storage (this includes clearing or copying arrays in storage)
And...
Should I use Open-Zeppelin's safe math for this function?
function cleanTheKingsChest() public isOwner {
uint bal = address(this).balance;
address(owner).transfer(bal);
}
This will transfer all ether held by the contract to the owner’s address. There is no issue with the way you’re doing it.
The reason for the warning is because you are making a call out to another address. That address could itself be a contract with a custom defined transfer or fallback function (if no transfer method is defined). Since Remix doesn’t know what that implementation may do, it’ can’t estimate the gas usage. This isn’t a concern since transfer calls are limited to a 2100 gas stipend.
You don’t need SafeMath for that function since you’re not doing anything that can cause an overflow. However, in general, it’s a good idea to use it.

What is an owning contact?

While going through solidity documentation I came across a term 'the owning contract' which i didnt understand.
A contract in the sense of Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. The line uint storedData; declares a state variable called storedData of type uint (unsigned integer of 256 bits). You can think of it as a single slot in a database that can be queried and altered by calling functions of the code that manages the database. In the case of Ethereum, this is always the owning contract. And in this case, the functions set and get can be used to modify or retrieve the value of the variable.
The owning contract means the contract that owns that block of storage on the Ethereum blockchain. The contract that "owns" this memory block is allowed to execute functions that read/write/delete/update the block's contents.
See this answer for a discussion of the two types of "memory/storage"

How to get transactions invoked by smart contract from blockchain

I want to get all receipt records of some address (address A) from blockchain. I use web3.eth.getBlock and web3.eth.getTransaction to get all transactions related to A.
But I find if ethers are transfered to address A by invoking 'A.send' or 'A.transfer' function in contract, I can only get a contract call transaction which from caller address to contract address. And I can't find relationship between this transaction and address A.
Is there any way to get transactions invoked by contract for A?
Thanks.
Short answer: listen to events instead of monitoring transactions.
Why can't I find the transactions "invoked by" the contract?
A contract does not invoke/create its own transaction (it doesn't have a private key to sign one). A contract can call other contracts during its own execution, as you've seen, but those calls are all executed as part of the same transaction.
The recommended way to discover executed function calls is to use events. If the contract you want to watch does not specify an event on the call you want to watch, you may be in for some heavy lifting: tracing every transaction's execution at the EVM level (something that big block explorers do to generate some of the extra info they provide).
If you are stuck tracing: you can find more about using ethereumjs-vm or geth's debug_traceTransaction on this Ethereum StackExchange Question about internal transactions.