{"action":"created","issue":{"url":"https://api.github.com/repos/EOSIO/eos/issues/4872","repository_url":"https://api.github.com/repos/EOSIO/eos","labels_url":"https://api.github.com/repos/EOSIO/eos/issues/4872/labels{/name}","comments_url":"https://api.github.com/repos/EOSIO/eos/issues/4872/comments","events_url":"https://api.github.com/repos/EOSIO/eos/issues/4872/events","html_url":"https://github.com/EOSIO/eos/issues/4872","id":344680664,"node_id":"MDU6SXNzdWUzNDQ2ODA2NjQ=","number":4872,"title":"Does \"asset\" type handle overflow/underflow protection by default?","user":{"login":"mochunhei","id":19904072,"node_id":"MDQ6VXNlcjE5OTA0MDcy","avatar_url":"https://avatars2.githubusercontent.com/u/19904072?v=4","gravatar_id":"","url":"https://api.github.com/users/mochunhei","html_url":"https://github.com/mochunhei","followers_url":"https://api.github.com/users/mochunhei/followers","following_url":"https://api.github.com/users/mochunhei/following{/other_user}","gists_url":"https://api.github.com/users/mochunhei/gists{/gist_id}","starred_url":"https://api.github.com/users/mochunhei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mochunhei/subscriptions","organizations_url":"https://api.github.com/users/mochunhei/orgs","repos_url":"https://api.github.com/users/mochunhei/repos","events_url":"https://api.github.com/users/mochunhei/events{/privacy}","received_events_url":"https://api.github.com/users/mochunhei/received_events","type":"User","site_admin":false},"labels":[{"id":577293330,"node_id":"MDU6TGFiZWw1NzcyOTMzMzA=","url":"https://api.github.com/repos/EOSIO/eos/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":{"login":"sergmetelin","id":2141500,"node_id":"MDQ6VXNlcjIxNDE1MDA=","avatar_url":"https://avatars1.githubusercontent.com/u/2141500?v=4","gravatar_id":"","url":"https://api.github.com/users/sergmetelin","html_url":"https://github.com/sergmetelin","followers_url":"https://api.github.com/users/sergmetelin/followers","following_url":"https://api.github.com/users/sergmetelin/following{/other_user}","gists_url":"https://api.github.com/users/sergmetelin/gists{/gist_id}","starred_url":"https://api.github.com/users/sergmetelin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergmetelin/subscriptions","organizations_url":"https://api.github.com/users/sergmetelin/orgs","repos_url":"https://api.github.com/users/sergmetelin/repos","events_url":"https://api.github.com/users/sergmetelin/events{/privacy}","received_events_url":"https://api.github.com/users/sergmetelin/received_events","type":"User","site_admin":false},"assignees":[{"login":"sergmetelin","id":2141500,"node_id":"MDQ6VXNlcjIxNDE1MDA=","avatar_url":"https://avatars1.githubusercontent.com/u/2141500?v=4","gravatar_id":"","url":"https://api.github.com/users/sergmetelin","html_url":"https://github.com/sergmetelin","followers_url":"https://api.github.com/users/sergmetelin/followers","following_url":"https://api.github.com/users/sergmetelin/following{/other_user}","gists_url":"https://api.github.com/users/sergmetelin/gists{/gist_id}","starred_url":"https://api.github.com/users/sergmetelin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergmetelin/subscriptions","organizations_url":"https://api.github.com/users/sergmetelin/orgs","repos_url":"https://api.github.com/users/sergmetelin/repos","events_url":"https://api.github.com/users/sergmetelin/events{/privacy}","received_events_url":"https://api.github.com/users/sergmetelin/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2018-07-26T03:22:34Z","updated_at":"2018-11-01T06:42:34Z","closed_at":"2018-11-01T06:42:34Z","author_association":"NONE","body":"From asset.hpp (https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/asset.hpp)\r\nIt seems that the asset type has overflow/underflow protection built-in. For example:\r\n```\r\n      asset& operator*=( int64_t a ) {\r\n         eosio_assert( a == 0 || (amount * a) / a == amount, \"multiplication overflow or underflow\" );\r\n         eosio_assert( -max_amount <= amount, \"multiplication underflow\" );\r\n         eosio_assert( amount <= max_amount,  \"multiplication overflow\" );\r\n         amount *= a;\r\n         return *this;\r\n      }\r\n```\r\n\r\nHowever, I did a test, and the result seems to show that there is no overflow/underflow protection.\r\nTest:\r\n```\r\n    uint64_t testa = 10000000000000000000;\r\n    asset test_asset = asset(1, string_to_symbol(4, \"EOS\")) * testa;\r\n\r\n    print(\"|\");\r\n    print(test_asset);\r\n    print(\"|\");\r\n    print(test_asset.amount);\r\n    print(\"|\");\r\n```\r\nResult:\r\n```\r\n>> |-844674407370955./*/* EOS|-8446744073709551616|\r\n```\r\n\r\nSo, did I do anything wrong or what?\r\nIf there is no protection by default, what is the best way to prevent overflow/underflow attack?"},"comment":{"url":"https://api.github.com/repos/EOSIO/eos/issues/comments/434947359","html_url":"https://github.com/EOSIO/eos/issues/4872#issuecomment-434947359","issue_url":"https://api.github.com/repos/EOSIO/eos/issues/4872","id":434947359,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNDk0NzM1OQ==","user":{"login":"dixia","id":667070,"node_id":"MDQ6VXNlcjY2NzA3MA==","avatar_url":"https://avatars3.githubusercontent.com/u/667070?v=4","gravatar_id":"","url":"https://api.github.com/users/dixia","html_url":"https://github.com/dixia","followers_url":"https://api.github.com/users/dixia/followers","following_url":"https://api.github.com/users/dixia/following{/other_user}","gists_url":"https://api.github.com/users/dixia/gists{/gist_id}","starred_url":"https://api.github.com/users/dixia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dixia/subscriptions","organizations_url":"https://api.github.com/users/dixia/orgs","repos_url":"https://api.github.com/users/dixia/repos","events_url":"https://api.github.com/users/dixia/events{/privacy}","received_events_url":"https://api.github.com/users/dixia/received_events","type":"User","site_admin":false},"created_at":"2018-11-01T06:42:34Z","updated_at":"2018-11-01T06:42:34Z","author_association":"NONE","body":"fixed"}}
{"actor":{"display_login":"dixia"}}