Let's suppose we are new to Ethereum (for instance, it is true for me) and want to write a smart contract! What should we do?
The logical thing is to start with architecture overview!
- We see there are externally-owned and contract accounts; externally-owned can transfer ETH and tokens... wait... are tokens a thing defined by the blockchain structure? If tokens need a rework, blockchain will need to be changed?
- Then, all accounts have nonce values; it has different meaning based on whether account is a smart contract (number of transactions sent versus number of contracts created). Also, the blockchain core somewhy takes responsibility of deduplicating transactions.
- EVM code gets executed if the account gets a message call - are there other kinds of messages?
- storageRoot – Sometimes known as a storage hash. A 256-bit hash of the root node of a Merkle Patricia trie that encodes the storage contents of the account (a mapping between 256-bit integer values) - contract storage is flat? What if one needed to store two mappings from user address to their data in a contract?
- When going further, we notice variety of modifiers on functions (payable, view, pure, external...)
I believe system of TON Blockchain (The Open Network) here is much straighter:
- TON operates on accounts as well. They are all smart contracts (contain code, balance and data).
- Externally-owned Ethereum accounts translate to wallet contracts - special programs that keep user's public key in data and, upon reception of external messages, validate signature and perform the corresponding actions.
- Wallet contracts can be different and even created by developers, without any need for approval from someone else.
- Users can change signature validation method, using secp256k1 or any method they like instead of Ed25519. They may abandon asymmetric cryptography altogether!
- Wallets can include additional functionality, like restricting destination addresses to a specific set (so you can provide someone funds for staking without ability to spend them all on NFTs) or etc.
- Messages are blobs of data, either imported into blockchain from the outer world (they are called external) or carrying value from one contract to another internally.
- Transaction is an update on contract state when it processes incoming message. Contracts are isolated: to interact with others, they send outgoing messages.
- From validators' point of view, each transaction can be computed efficiently due to being related to one account only.
- From developers' point of view, interacting with malicious contract cannot interrupt normal operation of your (compare with reentrancy concerns in Ethereum) or cause gas exhaustion.
- From users' point of view, a malicious contract cannot do anything to their assets even if user is sending messages to it! TON, tokens (jettons) and NFTs are all kept secure.
Top comments (0)