Struct sway_core::asm_generation::evm::EvmAsmBuilder
source · pub struct EvmAsmBuilder<'ir> { /* private fields */ }
Expand description
A smart contract is created by sending a transaction with an empty “to” field. When this is done, the Ethereum virtual machine (EVM) runs the bytecode which is set in the init byte array which is a field that can contain EVM bytecode
The EVM bytecode that is then stored on the blockchain is the value that is returned by running the content of init on the EVM.
The bytecode can refer to itself through the opcode CODECOPY opcode, which reads three values on the stack where two of those values are pointers to the bytecode, one marking the beginning and one marking the end of what should be copied to memory.
The RETURN opcode is then used, along with the correct values placed on the stack, to return bytecode from the initial run of the EVM code. RETURN reads and removes two pointers from the stack. These pointers define the part of the memory that is a return value. The return value of the initial contract creating run of the bytecode defines the bytecode that is stored on the blockchain and associated with the address on which you have created the smart contract.
The code that is compiled but not stored on the blockchain is thus the code needed to store the correct code on the blockchain but also any logic that is contained in a (potential) constructor of the contract.