Aptos 백서

Aptos

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 4쪽 중 2쪽

ruct USD {} struct JPY {} struct MultiCurrencyWallet has key, store { usd: Coin<USD>, jpy: Coin<JPY>, } .. } 0x1 0x2 0x3 Figure 2: Example on-chain Move modules. To create a new account, a user first generates a signature key-pair: (vk, sk). Next, the new account address for a given signature scheme is derived using the cryptographic hashH of the public verification key vk that is concatenated with the signature scheme identifier ( ssid): where addr = H(vk, ssid). After the new account is created at address addr, the user can sign transactions to be sent from the account at addr, using the private signing key sk. The user can also rotate sk, either to proactively change sk or to respond to a possible compromise. This will not change the account address, as the account address is derived only once, during its creation, from the public verification key. The Aptos blockchain does not link accounts to a real-world identity. A user can create multiple accounts by generating multiple key-pairs. Accounts controlled by the same user have no inherent link to each other. However, a single user can still manage multiple accounts in a single wallet for simple asset management. This flexibility provides pseudonymity for users while we experiment with privacy-preserving primitives for future releases. Multiple accounts owned by a single user or a set of users also provide channels to increase execution concurrency, as described in Section 7.4. 5.3 Move modules A Move module contains Move bytecode that declares data types (structs) and procedures. It is identified by the address of the account where the module is declared along with a module name. For example, the identifier for the first currency module in Figure 2 is 0x1::coin. A module can depend on other on-chain modules, as shown by the wallet module in Figure 2, enabling code reuse. A module must be uniquely named within an account, i.e., each account can declare at most one module with any given name. For example, the account at address 0x1 in Figure 2 could not declare another module named coin. On the other hand, the account at address 0x3 could declare a module named coin and the identifier of this module would be 0x3::coin. Note that 0x1::coin::Coin and 0x3::coin::Coin are distinct types and cannot be used interchangeably nor share common module code. In contrast, 0x1::coin::Coin<0x2::wallet::USD> and 0x1::coin::Coin<0x2::wallet::JPY> are different instantiations of the same generic type that cannot be used interchangeably but can share common module code. Modules are grouped into packages located at the same address. An owner of this address publishes the package as a whole on-chain, including the bytecode and package metadata. The package meta- data determines whether a package can be upgraded or is immutable. For an upgradeable package, compatibility checks are performed before the upgrade is permitted: no existing entry point functions must be changed and no resources can be stored in memory. However, new functions and resources can be added. The Aptos framework, consisting of the core libraries and configuration for the Aptos blockchain, is defined as a regular upgradeable package of modules (see Section 9.2). 6 0x2::wallet::Wallet { usd: 0x1::coin::Coin<0x2::wallet::USD> { value: 0, } jpy: 0x1::coin::Coin<0x2::wallet::JPY> { value: 10, } } module my_coin { struct MyCoin {} .. } 0x1::coin::Coin<0x60::my_coin::MyCoin> { value: 50, } 0x3::coin::Coin { value: 100, } 0x50 0x60 Figure 3: Example on-chain data. 5.4 Resources Similar to modules, account addresses can also have data values associated with them. Within each account address, the values are keyed by their types, with at most one value of each type belonging to the account. Figure 3 provides an example of this. Address 0x50 holds a single value, with 0x3::coin::Coin being the fully-qualified type. 0x3 is the address where the coin module is stored, coin is the name of the module and Coin is the name of the data type. Values of generic types are also allowed, with different instantiations being treated as distinct types. This is essential for extensibility, allowing different instantiations to share the same functional code. The rules for mutating, deleting, and publishing a value are encoded in the module that defines the data type. Move’s safety and verification rules prevent other code or entities from directly creating, modifying, or deleting instances of data types defined in other modules. Having at most one top-level value of each type under an address may at first sound limiting. However, this is not a problem in practice as programmers can define wrapper types with other data as internal fields, thus avoiding any limitations. The Wallet struct in Figure 3 is an example of how to use wrapper types. It should also be noted that not all data types can be stored on-chain. For data instances to qualify as top-level values, the data type must have the key ability. Similarly, the store ability is required for nested values. Data types with both abilities are also called resources. 5.5 Ledger state From the perspective of the Move virtual machine (Move VM), each account consists of a set of values and key-value data structures. These data structures are called table entries and are stored in the Binary Canonical Serialization format (BCS). This data layout enables developers to write smart contracts that can operate efficiently on small amounts of data replicated across a large number of accounts, as well as on large amounts of data stored in a small number of accounts. Move modules are stored similarly to account data but under an independent namespace. The genesis ledger state defines the initial set of accounts and their associated state at blockchain initialization. At launch, the Aptos blockchain will be represented by a single ledger state. However, as adoption increases and technology develops, Aptos will scale up the number of shards to increase throughput (i.e., enable multiple ledger states) and support transactions that move or access assets across shards. Each ledger state will maintain all on-chain assets for the specific shard and provide the same account model with a fine-grained, key-value data store offering near-fixed costs for storage access. 6 A safe user experience To reach billions of Internet users, the web3 user experience must be safe and accessible. In the sections below, we describe several innovations provided by the Aptos blockchain that work towards this goal. 7 6.1 Transaction viability protection Signing a transaction means that the signer authorizes the transaction to be committed and executed by the blockchain. Occasionally, users may sign transactions unintentionally or without fully considering all the ways in which their transactions might be manipulated. To reduce this risk, the Aptos blockchain constrains the viability of every transaction and protects the signer from unbounded validity. There are currently three different protections provided by the Aptos blockchain - the sender’s sequence number, a transaction expiration time, and a designated chain identifier. • A transaction’s sequence number can only be committed exactly once for each sender’s account. As a result, senders can observe that if the current account sequence number is ≥ the sequence number of a transaction t, then either t has already been committed or t will never be committed (as the sequence number used by t has already been consumed by another transaction). • The blockchain time advances with high precision and frequency (typically sub-second), as de- tailed in Section 7.3.1. If the blockchain time exceeds the expiration time of transaction t, then similarly, either t has already been committed or t will never be committed. • Every transaction has a designated chain identifier to prevent malicious entities from replaying transactions between different blockchain environments (e.g., across a testnet and mainnet). 6.2 Move-based key management As discussed in Section 5.2, Aptos accounts support key rotation, an important feature that can help reduce the risks associated with private key compromise, long-range attacks, and future advances that might break existing cryptographic algorithms. In addition, Aptos accounts are also flexible enough to enable new hybrid models of custody. In one such model, a user can delegate the ability to rotate the account’s private key to one or more custodians and other trusted entities. A Move module can then define a policy that empowers these trusted entities to rotate the key under specific circumstances. For example, the entities might be represented by a k-out-of-n multi-sig key held by many trusted parties and offer key recovery services to prevent user key loss (e.g., 20% of Bitcoin is currently locked up in unrecoverable accounts [7]). Moreover, while many wallets support various key recovery schemes, such as backing up private keys to cloud infrastructure, multi-party computation, and social recovery, they are typically implemented without blockchain support (i.e., off-chain). As a result, each wallet needs to implement its own key management infrastructure and related operations become opaque to users. In contrast, supporting key management functionality at the Aptos blockchain layer provides full transparency of all key-related operations and makes it simpler to implement a wallet with rich key management. 6.3 Pre-signing transaction transparency Today, wallets provide very little transparency about the transactions they sign. As a result, users are often easily tricked into signing malicious transactions that may steal funds and have devastating consequences. This is true even for blockchains that require enumerating all on-chain data accessed by each transaction. As a result, there are few user safeguards currently in place, making users vulnerable to a wide variety of attacks. To address this, the Aptos ecosystem provides services for transaction pre-execution: a precaution- ary measure that describes to users (in human-readable form) the outcomes of their transactions prior to signing. Pairing this with a known history of prior attacks and malicious smart contracts will help to reduce fraud. In addition, Aptos also enables wallets to dictate constraints on transactions during execution. Violating these constraints will result in the transactions being aborted, to further protect users from malicious applications or social engineering attacks. 6.4 Practical light client protocols Relying solely on the TLS/SSL certificates of API providers to establish trust between blockchain clients and servers does not protect clients sufficiently. Even in the presence of valid certificates, wallets and clients have no guarantees as to the authenticity and integrity of the data being presented 8 Validator Continuous transaction dissemination Client Submits transaction Block metadata ordering Parallel transaction execution Batch storage Ledger certification Other validators Batch transactions and share batches to other validators Other validators Group batches of metadata into blocks and order Other validators Periodically, share and aggregate signatures on the ledger state Other validators If required, fetch the batches of transactions Figure 4: The transaction processing life cycle. All stages are completely independent and are indi- vidually parallelizable. to them. As a result, API providers may return incorrect or malicious blockchain data, deceiving third parties and performing double-spend attacks. To prevent this, Aptos provides state proofs and light client verification protocols that can be used by wallets and clients to verify the validity of data being presented by an untrusted third-party server. Moreover, by leveraging the timestamp-based state proofs in Section 7.6.2, light clients can always ensure tight bounds on the freshness of account state (e.g., within seconds) and only need to track changes in the network configuration ( epoch changes) or use current trusted checkpoints ( waypoints) to stay up-to-date [8]. By combining high-frequency timestamps and inexpensive state proofs, the Aptos blockchain provides increased security guarantees to clients. In addition, Aptos nodes also expose rich, high-performance storage interfaces that can be further fine-tuned to allow subscriptions to proofs targeting specific data and accounts on-chain. This can be leveraged by light clients to retain minimal verifiable data without the need to run a full node or process a substantial number of transactions. 7 Pipelining, batching, and parallel transaction processing To maximize throughput, increase concurrency, and reduce engineering complexity, transaction pro- cessing on the Aptos blockchain is divided into separate stages. Each stage is completely independent and individually parallelizable, resembling modern, superscalar processor architectures. Not only does this provide significant performance benefits, but also enables the Aptos blockchain to offer new modes of validator-client interaction. For example: • Clients can be notified when specific transactions have been included in a batch of persisted transactions. Persisted and valid transactions are highly likely to be committed imminently. • Clients can be informed when a batch of persisted transactions has been ordered. Thus, to reduce the latency of determining the executed transaction outputs, clients can select to execute transactions locally rather than wait for the validators to complete execution remotely. • Clients can elect to wait for certified transaction execution by the validators and perform state synchronization on the attested results (e.g., see section 8). The Aptos modular design aids development speed and supports faster release cycles, as changes can be targeted to individual modules, instead of a single monolithic architecture. Similarly, the modular design also provides a structured path to scaling validators beyond a single machine, providing access to additional compute, network, and storage resources. Figure 4 shows the transaction life cycle across the various processing stages. 7.1 Batch processing Batch processing is an important efficiency optimization that is part of every phase of operation in the Aptos blockchain. Transactions are grouped into batches by each validator during transaction dissemination, and batches are combined into blocks during consensus. The execution, storage, and 9 block_timestamp=9 (digest_0, timestamp_0, PoAV_0) transaction transaction transaction (digest_2, timestamp_2, PoAV_2) transaction transaction transaction (digest_7, timestamp_7, PoAV_7) transaction transaction transaction block_timestamp=11 (digest_3, timestamp_3, PoAV_3) transaction transaction transaction (digest_1, timestamp_1, PoAV_1) transaction transaction transaction (digest_4, timestamp_4, PoAV_4) transaction transaction transaction Figure 5: Block metadata ordering occurs independently from transaction dissemination. ledger certification phases also work in batches to provide opportunities for reordering, reduction of operations (e.g., duplicate computation or signature verification), and parallel execution. Grouping transactions into batches can induce small amounts of latency, for example, waiting 200 milliseconds to accumulate a batch of transactions before performing dissemination. However, batching is easily configurable with respect to a maximum waiting period and maximum batch size, enabling a decentralized network to automatically optimize across latency and efficiency. Batching also allows for efficient fee markets to prioritize transactions and avoid unintended denial-of-service (DoS) attacks from overzealous clients. 7.2 Continuous transaction dissemination Following the primary insight of Narwhal & Tusk [9], transaction dissemination in the Aptos blockchain is decoupled from consensus. Validators continuously stream batches of transactions to each other, utilizing all available network resources concurrently. Each batch distributed by a validator v is persisted, and a signature on the batch digest is sent back to v. Following the consensus requirements defined in Section 7.3, any 2 f + 1 stake weighted signatures on the batch digest form a proof of availability (PoAv). Such a proof guarantees that at least f + 1 stake weighted honest validators have stored the batch, and thus all honest validators will be able to retrieve it prior to execution. Infinitely persisting batches of transactions can open a DoS attack vector by causing validators to run out of storage and crash. To prevent this, each batch of transactions has an associated timestamp. The timestamp on the batch allows efficient garbage collection at each validator. In addition, a separate per-validator quota mechanism is designed to protect validators from running out of space even in the most extreme circumstances, such as under potential byzantine attacks. Batches also have sizing constraints that are validated prior to agreement to persist to stable storage. Finally, several optimizations to de-duplicate and cache transactions reduce storage costs and ensure performant integration with the parallel execution engine. 7.3 Block metadata ordering One common misconception is that consensus is slow and therefore the primary bottleneck for blockchain throughput and latency. One of the key innovations of the Aptos blockchain is to decouple non- agreement related tasks out of the consensus phase, such as transaction dissemination, transaction execution/storage, and ledger certification. By decoupling transaction dissemination from the consen- sus phase, ordering can occur with very low bandwidth (block metadata and proofs only), resulting in high transaction throughput and minimized latency. Today, the Aptos blockchain leverages the latest iteration of DiemBFTv4 [10], an optimistically responsive BFT consensus protocol. Consensus in the common case only requires two network round trips (with round trip times typically less than 300 milliseconds worldwide) and dynamically adjusts to faulty validators through a leader reputation mechanism [11]. The on-chain leader reputation 10 mechanism promotes validators that have successfully committed blocks in a window and demotes validators that are not participating. This novel mechanism significantly improves performance in decentralized environments, correspondingly provides infrastructure for appropriate incentives, and quickly minimizes the impact of failed validators on throughput and latency. DiemBFTv4 guarantees liveness under partial synchrony and ensures safety under asynchrony where the total validator stake is ≥ 3f + 1 with up to f stake-weighted faulty validators. DiemBFTv4 has been extensively tested in several iterations since 2019 with dozens of node operators and a multi- wallet ecosystem. We are also experimenting with our recent research (e.g., Bullshark [12]) and other protocols that rely on the block history and associated communication to determine block metadata ordering and finality. A consensus block and a proposal timestamp are proposed by a leader and agreed upon by the other validators as shown in Figure 5. Note that each consensus block contains only the batch metadata and proofs. Actual transactions are not required in the block, as the PoA V ensure that the batches of transactions will be available at the execution phase after ordering (see Section 7.2). Validators may vote on a leader’s proposal after verifying the proof and the block metadata criteria are met (e.g., proposal timestamp ≤ block expiration time). 7.3.1 Blockchain time The Aptos blockchain adopts an approximate, agreed-upon, physical timestamp for every proposed block, and correspondingly, all transactions within that block. This timestamp enables many important use cases. For example: • Time-dependent logic in smart contracts. For instance, a developer wo
프로젝트로 돌아가기