{"action":"created","issue":{"url":"https://api.github.com/repos/ethereum/EIPs/issues/28","labels_url":"https://api.github.com/repos/ethereum/EIPs/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/ethereum/EIPs/issues/28/comments","events_url":"https://api.github.com/repos/ethereum/EIPs/issues/28/events","html_url":"https://github.com/ethereum/EIPs/issues/28","id":118172215,"number":28,"title":"EIP 101 (Serenity): Currency and Crypto Abstraction","user":{"login":"vbuterin","id":2230894,"avatar_url":"https://avatars.githubusercontent.com/u/2230894?v=3","gravatar_id":"","url":"https://api.github.com/users/vbuterin","html_url":"https://github.com/vbuterin","followers_url":"https://api.github.com/users/vbuterin/followers","following_url":"https://api.github.com/users/vbuterin/following{/other_user}","gists_url":"https://api.github.com/users/vbuterin/gists{/gist_id}","starred_url":"https://api.github.com/users/vbuterin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vbuterin/subscriptions","organizations_url":"https://api.github.com/users/vbuterin/orgs","repos_url":"https://api.github.com/users/vbuterin/repos","events_url":"https://api.github.com/users/vbuterin/events{/privacy}","received_events_url":"https://api.github.com/users/vbuterin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ethereum/EIPs/labels/EIP","name":"EIP","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":44,"created_at":"2015-11-21T05:30:51Z","updated_at":"2016-01-25T04:23:54Z","closed_at":null,"body":"### Title\r\n\r\n      EIP: 101\r\n      Title: Serenity Currency and Crypto Abstraction\r\n      Author: Vitalik Buterin <v@buterin.com>\r\n      Status: Active\r\n      Type: Serenity feature\r\n      Created: 2015-11-15\r\n\r\n### Specification\r\n\r\n1.  Accounts now have only two fields in their RLP encoding: **code** and **storage**.\r\n2.  Ether is no longer stored in account objects directly; instead, at address `0`, we premine a contract which contains all ether holdings. The `eth.getBalance` command in web3 is remapped appropriately.\r\n3.  `msg.value` no longer exists as an opcode, and neither does `tx.gasprice`\r\n4.  A transaction now only has four fields: **to**, **startgas**, **data** and **code**.\r\n5.  Aside from an RLP validity check, and checking that the **to** field is twenty bytes long, the **startgas** is an integer, and **code** is either empty or hashes to the **to** address, there are no other validity constraints; anything goes. However, the block gas limit remains, so miners are disincentivized from including junk.\r\n6.  Gas is charged for bytes in **code** at the same rate as **data**.\r\n7.  When a transaction is sent, if the receiving account does not yet exist, the account is created, and its code is set to the code provided in the transaction; otherwise the code is ignored.\r\n8.  A `tx.gas` opcode is added alongside the existing `msg.gas` at index `0x5c`; this new opcode allows the transaction to access the original amount of gas allotted for the transaction\r\n\r\nNote that `ECRECOVER`, sequence number/nonce incrementing and ether are now nowhere in the bottom-level spec (NOTE: ether is going to continue to have a privileged role in Casper PoS). To replicate existing functionality under the new model, we do the following.\r\n\r\nSimple user accounts can have the following default standardized code:\r\n\r\n```python\r\n# We assume that data takes the following schema:\r\n# bytes 0-31: v (ECDSA sig)\r\n# bytes 32-63: r (ECDSA sig)\r\n# bytes 64-95: s (ECDSA sig)\r\n# bytes 96-127: sequence number (formerly called \"nonce\")\r\n# bytes 128-159: gasprice\r\n# bytes 172-191: to\r\n# bytes 192+: data\r\n\r\n# Get the hash for transaction signing\r\n~mstore(0, msg.gas)\r\n~calldatacopy(32, 96, ~calldatasize() - 96)\r\nh = sha3(96, ~calldatasize() - 96)\r\n# Call ECRECOVER contract to get the sender\r\n~call(5000, 3, [h, ~calldataload(0), ~calldataload(32), ~calldataload(64)], 128, ref(addr), 32)\r\n# Check sender correctness\r\nassert addr == 0x82a978b3f5962a5b0957d9ee9eef472ee55b42f1\r\n# Check sequence number correctness\r\nassert ~calldataload(96) == self.storage[-1]\r\n# Increment sequence number\r\nself.storage[-1] += 1\r\n# Make the sub-call and discard output\r\n~call(msg.gas - 50000, ~calldataload(160), 192, ~calldatasize() - 192, 0, 0)\r\n# Pay for gas\r\n~call(40000, 0, [SEND, block.coinbase, ~calldataload(128) * (tx.gas - msg.gas + 50000)], 96, 0, 0)\r\n```\r\n\r\nThis essentially implements signature and nonce checking, and if both checks pass then it uses all remaining gas minus 50000 to send the actual desired call, and then finally pays for gas.\r\n\r\nMiners can follow the following algorithm upon receiving transactions:\r\n\r\n1.  Run the code for a maximum of 50000 gas, stopping if they see an operation or call that threatens to go over this limit\r\n2.  Upon seeing that operation, make sure that it leaves at last 50000 gas to spare (either by checking that the static gas consumption is small enough or by checking that it is a call with `msg.gas - 50000` as its gas limit parameter)\r\n3.  Pattern-match to make sure that gas payment code at the end is *exactly* the same as in the code above.\r\n\r\nThis process ensures that miners *waste* at most 50000 gas before knowing whether or not it will be worth their while to include the transaction, and is also highly general so users can experiment with new cryptography (eg. ed25519, Lamport), ring signatures, quasi-native multisig, etc. Theoretically, one can even create an account for which the *valid signature* type is a valid Merkle branch of a receipt, creating a quasi-native alarm clock.\r\n\r\nIf someone wants to send a transaction with nonzero value, instead of the current `msg.sender` approach, we compile into a three step process:\r\n\r\n1.  In the outer scope just before calling, call the ether contract to create a cheque for the desired amount\r\n2.  In the inner scope, if a contract uses the `msg.value` opcode anywhere in the function that is being called, then we have the contract cash out the cheque at the start of the function call and store the amount cashed out in a standardized address in memory\r\n3.  In the outer scope just after calling, send a message to the ether contract to disable the cheque if it has not yet been cashed\r\n\r\n### Rationale\r\n\r\nThis allows for a large increase in generality, particularly in a few areas:\r\n\r\n1.  Cryptographic algorithms used to secure accounts (we could reasonably say that Ethereum is quantum-safe, as one is perfectly free to secure one's account with Lamport signatures). The nonce-incrementing approach is now also open to revision on the part of account holders, allowing for experimentation in k-parallelizable nonce techniques, UTXO schemes, etc.\r\n2.  Moving ether up a level of abstraction, with the particular benefit of allowing ether and sub-tokens to be treated similarly by contracts\r\n3.  Reducing the level of indirection required for custom-policy accounts such as multisigs\r\n\r\nIt also substantially simplifies and *purifies* the underlying Ethereum protocol, reducing the minimal consensus implementation complexity.\r\n\r\n### Implementation\r\n\r\nComing soon.\r\n"},"comment":{"url":"https://api.github.com/repos/ethereum/EIPs/issues/comments/174396268","html_url":"https://github.com/ethereum/EIPs/issues/28#issuecomment-174396268","issue_url":"https://api.github.com/repos/ethereum/EIPs/issues/28","id":174396268,"user":{"login":"wanderer","id":158211,"avatar_url":"https://avatars.githubusercontent.com/u/158211?v=3","gravatar_id":"","url":"https://api.github.com/users/wanderer","html_url":"https://github.com/wanderer","followers_url":"https://api.github.com/users/wanderer/followers","following_url":"https://api.github.com/users/wanderer/following{/other_user}","gists_url":"https://api.github.com/users/wanderer/gists{/gist_id}","starred_url":"https://api.github.com/users/wanderer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wanderer/subscriptions","organizations_url":"https://api.github.com/users/wanderer/orgs","repos_url":"https://api.github.com/users/wanderer/repos","events_url":"https://api.github.com/users/wanderer/events{/privacy}","received_events_url":"https://api.github.com/users/wanderer/received_events","type":"User","site_admin":false},"created_at":"2016-01-25T04:23:54Z","updated_at":"2016-01-25T04:23:54Z","body":"@christianlundkvist i'm more interested in making the VM fast enough that we don't need precompiles "}}