Machines deployed with smart contracts
Term Definitions Smart Contract A computer protocol designed to disseminate, verify, or execute contracts in an information-based manner. Blockchain A distributed database maintained by multiple participants to record transaction information. Bytecode An intermediate code that is not machine code for a specific processor but requires an interpreter to execute. Machine Code A low-level code that can be executed directly by a computer processor. AoT Compilation Ahead-of-Time Compilation A technology that compiles bytecode into machine code before the program runs. TEE A hardware or software component that provides a secure execution environment. KMS A server used to manage keys, such as distributing and revoking keys. Remote Attestation A mechanism used to verify the integrity and authenticity of a remote system. System Contract A predefined smart contract used to execute the core functions of a blockchain system. EVM A virtual machine used to execute smart contracts in the Ethereum blockchain. WASM (WebAssembly) is a portable bytecode format designed to improve the performance of web applications.
Short answer questions
Briefly describe what smart contracts are and what advantages they have over traditional contracts?
Explain what AoT compilation is and why it can improve the execution efficiency of smart contracts?
Why is there a security risk in directly deploying machine code to the blockchain?
What role does TEE play in the deployment of smart contracts?
Explain what remote attestation is and how it ensures the trustworthiness of TEE?
How does a blockchain node verify that machine code is generated by a trusted TEE?
What is a system contract and what role does it play in the machine code deployment process?
In addition to EVM, what other virtual machines can machine code be applied to?
What role does optimized compilation play in AoT compilation?
Briefly describe the process of deploying machine code to the blockchain.
Short answer questions
A smart contract is a computer protocol written in code that automatically executes the terms of the contract. Compared with traditional contracts, smart contracts have the advantages of decentralization, transparency, security, and efficiency, which can reduce transaction costs and improve execution efficiency.
AoT compilation is a technology that compiles bytecode into machine code before the program runs. Since machine code can be directly executed by the processor without interpretation, it can significantly improve the execution efficiency of smart contracts.
Since machine code has higher execution permissions, malicious attackers can steal private data on blockchain nodes by tampering with machine code, and even affect the normal operation of the blockchain network. Therefore, directly deploying unverified machine code to the blockchain will bring security risks.
TEE provides a secure execution environment for compiling bytecode into machine code before deploying smart contracts and signing the generated machine code. Blockchain nodes can ensure the security of machine code by verifying signatures.
Remote attestation is a mechanism for verifying the integrity and authenticity of remote systems. It can ensure that the software and hardware environment of TEE is trustworthy and has not been tampered with. TEE can obtain the private key distributed by KMS through remote attestation and use the private key to sign the generated machine code.
The blockchain node can determine whether the machine code is generated by a trusted TEE by verifying the signature of the TEE on the machine code. The blockchain node can obtain the public key corresponding to the trusted TEE image from the KMS and use the public key to verify the signature.
A system contract is a predefined smart contract used to execute the core functions of the blockchain system. During the machine code deployment process, the system contract can be used to verify the signature of the machine code to ensure that the machine code is generated by a trusted TEE.
In addition to EVM, machine code can also be applied to virtual machines such as WASM (WebAssembly) virtual machine and JSVM (JavaScript Virtual Machine). Any virtual machine that supports machine code execution can use this deployment method.
Optimized compilation can analyze the code structure and execution path, optimize the machine code to reduce the number of instructions and memory usage, and further improve the execution efficiency of smart contracts.
First, the user sends the bytecode of the smart contract to the TEE for AoT compilation. Then, the TEE generates the machine code and signs it with a private key. Finally, the user sends the transaction containing the machine code and signature to the blockchain network, and the blockchain node verifies the signature and completes the deployment.