Skip to content

Commit

Permalink
[Docs] Refine token_t documentation and add link in docs page
Browse files Browse the repository at this point in the history
  • Loading branch information
hydai committed Aug 9, 2018
1 parent 816a6b6 commit fe7193a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ERC Contract Standard Checker
Overflow Protection
```````````````````

- :ref:`token_t - a new type with native SafeMath support <token-type>`
- :ref:`Bec token with overflow protection <overflow-protection>`

Ethereum Native Interface (ENI)
Expand Down
18 changes: 11 additions & 7 deletions docs/token_t.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@
New Type for Secure Transaction
================================================================

.. _token-type:

At the begin of 2018, BEC smart contract were hacked because a human error. There is one and only mathematical operation forgot to use SafeMath Library and overflowed. In the Lity, we introduce a new type `token_t` in the language to help the Smart Contract developer keep the risk of overflow away.

Token Type
`````````````````
Token type `token_t` is a new type extend from `uint256`, `uint`. `token_t` type is not allowed implicit conversion to the other types.
----------

Lity provides a new type `token_t` which extends from `uint256`, `uint`. `token_t` is designed for calculating balance of token or any other unsigned integer with overflow protection by default. With this feature, developers don't need to care about how and where to use SafeMath library, because `token_t` will handle all of the conditions automatically.

Because of the security issue, `token_t` is not allowed implicit conversion to the other types. If you want to convert, tying to use explicit conversion like the example below:

.. code:: bash
token_t a = 2000;
token_t b = a * 12345;
//uint c = b; // Not Allowed
uint c = uint(a); // OK, use strict type conversion
// uint c = b; // Error: Implicit conversion is Not Allowed
uint c = uint(a); // OK: Explicit conversion uses strict type conversion
Otherwise, `token_t` will automatically check overflow during runtime on those operations : add, sub, mul. The behavior just like the SafeMath, but the developer could not to add it manually.
In addition, `token_t` will automatically check overflow during runtime on those operations: add, sub, mul. The behavior just like the SafeMath, but the developer could not to add it manually.

Example
````````````````````
-------

.. code::
Expand Down Expand Up @@ -46,4 +51,3 @@ Let compile it with `lityc` and run the bytecode on evm. The evm will raise a IN
#### LOGS ####

0 comments on commit fe7193a

Please sign in to comment.