Understanding the Ethereum virtual machine is helpful to understand how smart contracts work and more importantly how they can be abused. This background knowledge is not needed to get started hacking smart contracts but understanding how the Ethereum virtual machine works can help you understand how the universal state works and how transactions operate.
I thought Ethereum was a crypto coin?
Ethereum refers to the whole blockchain network. The base token on the Ethereum network is Ether (ETH). This native token is used to pay for gas fees and is required for deploying and interacting with smart contracts. Ethereum is a blockchain just like Bitcoin, well... not quite "just like bitcoin". See, Ethereum having a virtual machine enables for a universal state machine. This means that every time there is a new block added to the blockchain there could be potential updates to variables held in the global scope.
Think of the VM as one main program thread with shared memory space where new programs can read existing variables. Those variables can be updated as long as they follow the rules laid out by the code that deployed them. So for example here is a simple smart contract that sets a variable. The variable can only be set by the creator of the smart contract (aka the "owner").
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
/**
* @title SimpleStorage
* @dev Store & retrieve value in a variable
* @custom:dev-run-script ./scripts/deploy_with_ethers.ts
*/
contract SimpleStorage {
uint256 myNum;
address public owner = msg.sender;
/**
* @dev Store value in variable
* @param _val value to store
*/
function store(uint256 _val) public {
//make sure only the owner can set the variable
require(msg.sender == owner);
myNum = _val;
}
/**
* @dev Return value
* @return value of 'number'
*/
function retrieve() public view returns (uint256){
return myNum;
}
}