Ethereum is one of the most promising cryptocurrency systems available today. Its coin is known as ether. The programs that run on ethereum’s virtual machine are known as smart contracts and are enforced automatically via the blockchain’s transaction validation process which is carried out by the network’s full nodes.
Ethereum provided an ideal platform for scripting smart contracts. Oppositely to bitcoin, scripting smart contracts permits looping via using both recursive and jump calls. If looping was not limited, an adversary could successfully execute Denial of Service (DoS) attacks via sending a transaction that loops infinitely, due to the fact that every node validates each and every smart contract. To prevent this from happening, ethereum’s algorithm limits the time of execution of each transaction, this execution time limit is known as “gas”.
What is Gas?
Gas represents the amount of gas, which is paid in advance when a transaction is initiated, that covers the fees of completing it successfully. Whenever a transaction runs out of its gas, during its execution, it will be reversed, or refunded, yet the consumed amount of gas won’t be refunded.
When you create an ethereum transaction, you chose to specify the maximum amount of gas you are willing to pay for its execution. As such, miners usually can detect transactions that will take long time to be validated without literally having to calculate their results.
Transactions of ethereum’s blockchain permit the creation of standalone smart contracts that are stored on the blockchain and can include data, ether, executable computer code, can interact with other smart contracts and even create new smart contracts too.
Smart contracts behave as users on the ethereum network, with the only difference that they do not have the ability to initiate transactions by themselves. This limitation was intentionally imposed to prevent DoS attacks against existing smart contracts. As such, the gas needed to run the code triggered by a given transaction should be initially paid by the user who initiated the transaction in the first place.
Scripting smart contracts:
Ethereum’s smart contracts are coded in bytecode and run on EVM which has a fixed 32 bits word size and for simplicity, it is untyped. Ethereum ‘s EVM has a single slack which is limited to 1024 elements, it provides two forms of storage:
- Temporary memory which is represented by a byte array and is deleted once a transaction is executed.
- Permanent storage which is a key-value dictionary that is word-indexed, and is stored on the blockchain between executions, yet it can be deallocated explicitly.
Ethereum’s EVM programming language permits conditional as well as unconditional jump operations. To permit easier and more efficient implementations of JIT compilers, these jump operations act via only targeting specific code parts known as jump destinations.
New smart contracts can be created directly by users or by other smart contracts via the CREATE bytecode operator.
Through call operations, smart contracts can send messages to other smart contracts. This can permit sending of ether, executing the code of other smart contracts, to modify the maximum amount of gas consumed by the code executed via the call, and can receive and pass information.
Smart contracts on ethereum’s network have a single bytecode block which is executed by the call operations, yet high level programming languages, such as Solidity, automatically select a function selector at the start of the block which redirects call operations to the matching bytecode parts.
Image source: Flickr