Blockchain Node and Storage Media Learning Guide
Glossary
Term DefinitionsBlockchain A distributed database that uses cryptography to ensure data security and immutabilitySmart Contract A program stored on a blockchain that automatically executes when preset conditions are metBytecode An intermediate code that can be executed by a virtual machine and is platform-independentMachine Code A code that can be directly executed by a computer processorCompilation Execution Convert code written in a high-level language to machine code and then execute the machine codeInterpretation Execution Interpretation and execution of bytecode line by line by a virtual machineVirtual Machine A software that simulates a real computer systemEthereum Virtual Machine (EVM) A virtual machine used by the Ethereum blockchainJust-in-time compiler (JIT) A technology that compiles bytecode to machine code while the program is runningAhead-of-time compilation (AOT) A technology that compiles bytecode to machine code before the program runsTrusted Execution Environment (TEE) An execution environment that provides secure isolationSoftware Extension Guard (SGX) A TEE technology provided by Intel CPUEnclave An encrypted trusted execution area provided in SGXRemote Attestation (Remote Attestation) Attestation) A mechanism to verify the authenticity of TEE Test Questions
Short answer questions
What is the difference between interpreted execution and compiled execution?
Why does Ethereum use EVM to execute smart contracts?
What is JIT compilation? What are its advantages and disadvantages?
What is AOT compilation? What are its advantages and disadvantages compared to JIT compilation?
Why is a trusted execution environment (TEE) needed to compile the machine code of smart contracts?
How to verify whether TEE is trustworthy?
What is SGX? How does it protect data security?
What role does the system contract play in the deployment of smart contracts?
Explain the process of deploying smart contracts to the blockchain.
Explain how blockchain nodes call deployed smart contracts.
Answer
Interpreted execution is performed by the virtual machine line by line to interpret the bytecode and execute it, which is platform-independent but inefficient. Compiled execution converts the code into machine code and then executes the machine code, which is more efficient but lacks platform independence.
Ethereum uses EVM to execute smart contracts to ensure that the execution results of smart contracts on different nodes are consistent, because EVM can shield the differences in the underlying hardware and software environment.
JIT compilation compiles hot code into machine code when the program is running to improve execution efficiency. The advantage is that it takes into account both platform independence and execution efficiency, and the disadvantage is that the compilation process will take up running time.
AOT compilation compiles bytecode into machine code before the program runs. The advantage is high execution efficiency, and the disadvantage is that the information of the target platform needs to be known in advance, and the code size will increase.
TEE is needed to compile the machine code of smart contracts to ensure the security of machine code, because machine code is more easily tampered with than bytecode, which brings security risks.
The trustworthiness of TEE can be verified through remote attestation mechanism, such as using the digital signature provided by the CPU manufacturer to verify the status of TEE.
SGX is a TEE technology provided by Intel CPU, which protects data security by creating an encrypted trusted execution area (Enclave) in memory. The data in the Enclave can only be accessed inside the CPU to prevent malware attacks.
System contracts can be used to verify whether TEE is trustworthy, such as storing the public key corresponding to the trusted TEE image, and the blockchain node can verify the signature of the machine code by calling the system contract.
The process of deploying a smart contract includes: writing a smart contract, compiling it to bytecode, (optionally) using TEE to compile the bytecode to machine code, packaging the code into a transaction, sending the transaction to the blockchain network, the blockchain node verifying the transaction and executing it, creating a contract account and assigning an address.
The process of a blockchain node calling a deployed smart contract includes: the client initiates a transaction to call the contract, the transaction contains the contract address, calling functions and parameters, the blockchain node verifies the transaction and executes it, executes the contract code, and updates the contract status.
Paper title
Compare and contrast the advantages and disadvantages of interpreted execution, JIT compilation, and AOT compilation in smart contract execution, and discuss which method is more suitable for the future development of blockchain.
Explore the application of TEE in blockchain. In addition to compiling smart contracts, what other security and privacy improvements can TEE bring to blockchain?
Analyze the challenges faced by smart contract security and propose specific solutions to prevent smart contracts from being attacked or abused.
Study how to improve the execution efficiency of smart contracts. In addition to compilation optimization, what other methods can be used to improve the running speed of smart contracts?
Explore the future development direction of smart contracts. How will smart contracts change the existing business model and social life?