Giter VIP home page Giter VIP logo

eosio.contracts's Introduction

eosio.contracts

Version : 1.9.2

The design of the EOSIO blockchain calls for a number of smart contracts that are run at a privileged permission level in order to support functions such as block producer registration and voting, token staking for CPU and network bandwidth, RAM purchasing, multi-sig, etc. These smart contracts are referred to as the bios, system, msig, wrap (formerly known as sudo) and token contracts.

This repository contains examples of these privileged contracts that are useful when deploying, managing, and/or using an EOSIO blockchain. They are provided for reference purposes:

The following unprivileged contract(s) are also part of the system.

Dependencies:

Build

To build the contracts follow the instructions in Build and deploy section.

Contributing

Contributing Guide

Code of Conduct

License

MIT

The included icons are provided under the same terms as the software and accompanying documentation, the MIT License. We welcome contributions from the artistically-inclined members of the community, and if you do send us alternative icons, then you are providing them under those same terms.

Important

See LICENSE for copyright and license terms.

All repositories and other materials are provided subject to the terms of this IMPORTANT notice and you must familiarize yourself with its terms. The notice contains important information, limitations and restrictions relating to our software, publications, trademarks, third-party resources, and forward-looking statements. By accessing any of our repositories and other materials, you accept and agree to the terms of the notice.

eosio.contracts's People

Contributors

abourget avatar arhag avatar b1bart avatar brianjohnson5972 avatar bytemaster avatar deckb avatar deniscarriere avatar dskvr avatar elmato avatar eosauthority avatar heifner avatar hqueue avatar iamveritas avatar igorls avatar jeffreyssmith2nd avatar jgiszczak avatar josephjguerra avatar kesar avatar kj4ezj avatar larryk85 avatar lparisc avatar moskvanaft avatar revl avatar robertkowalski avatar scottarnette avatar spoonincode avatar taokayan avatar tbfleming avatar thomasbcox avatar zorba80 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eosio.contracts's Issues

eosio.system.abi struct definition lack of "base"

You should have "base":"" between "name" and "fields" in eosio.system.abi file.
Conflict with type definition.

{
      "name": "eosio_global_state2",
      "fields": [
         {"name":"new_ram_per_block",            "type":"uint16"},
         {"name":"last_ram_increase",            "type":"block_timestamp_type"},
         {"name":"last_block_num",               "type":"block_timestamp_type"},
         {"name":"total_producer_votepay_share", "type":"float64"},
         {"name":"revision",                     "type":"uint8"}
      ]
    },{
      "name": "eosio_global_state3",
      "fields": [
         {"name":"last_vpay_state_update",       "type":"time_point"},
         {"name":"total_vpay_share_change_rate", "type":"float64"}
      ]
    },

Proposal: Add blacklist in the system contract

Currently, the blacklist is manually added in the config.ini file, which is very detrimental to the update. With changes in BP, transactions will be allowed to pass to those who do not add the blacklist. This is not favorable.
It is recommended that this blacklist be added to the system contract.

@heifner @bytemaster

compile eosio.contracts/eosio.token fail (https://developers.eos.io/eosio-home/docs/token-contract)

I follow the steps below: (according to the example: https://developers.eos.io/eosio-home/docs/token-contract)
1、git clone https://github.com/EOSIO/eosio.contracts
2、cd eosio.contracts/eosio.token
3、eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp
4、found error:

In file included from src/eosio.token.cpp:6:
include/eosio.token/eosio.token.hpp:20:12: warning: unknown attribute 'contract' ignored [-Wunknown-attributes]
class [[eosio::contract("eosio.token")]] token : public contract {
^
include/eosio.token/eosio.token.hpp:41:39: error: unknown type name 'symbol'
void open( name owner, const symbol& symbol, name ram_payer );
^
include/eosio.token/eosio.token.hpp:44:40: error: unknown type name 'symbol'
void close( name owner, const symbol& symbol );
^
include/eosio.token/eosio.token.hpp:46:64: error: unknown type name 'symbol_code'
static asset get_supply( name token_contract_account, symbol_code sym_code )
^
include/eosio.token/eosio.token.hpp:53:77: error: unknown type name 'symbol_code'
static asset get_balance( name token_contract_account, name owner, symbol_code sym_code )
^
include/eosio.token/eosio.token.hpp:64:65: error: no member named 'code' in 'eosio::symbol_type'
uint64_t primary_key()const { return balance.symbol.code().raw(); }

include/eosio.token/eosio.token.hpp:72:64: error: no member named 'code' in 'eosio::symbol_type'
uint64_t primary_key()const { return supply.symbol.code().raw(); }
~~~~~~~~~~~~~ ^
src/eosio.token.cpp:20:34: error: no member named 'code' in 'eosio::symbol_type'
stats statstable( _self, sym.code().raw() );
~~~ ^
src/eosio.token.cpp:21:42: error: no member named 'code' in 'eosio::symbol_type'
auto existing = statstable.find( sym.code().raw() );
~~~ ^
src/eosio.token.cpp:38:34: error: no member named 'code' in 'eosio::symbol_type'
stats statstable( _self, sym.code().raw() );
~~~ ^
src/eosio.token.cpp:39:42: error: no member named 'code' in 'eosio::symbol_type'
auto existing = statstable.find( sym.code().raw() );
~~~ ^
src/eosio.token.cpp:50:28: error: use of undeclared identifier 'same_payer'
statstable.modify( st, same_payer, [&]( auto& s ) {
^
src/eosio.token.cpp:69:34: error: no member named 'code' in 'eosio::symbol_type'
stats statstable( _self, sym.code().raw() );
~~~ ^
src/eosio.token.cpp:70:42: error: no member named 'code' in 'eosio::symbol_type'
auto existing = statstable.find( sym.code().raw() );
~~~ ^
src/eosio.token.cpp:80:28: error: use of undeclared identifier 'same_payer'
statstable.modify( st, same_payer, [&]( auto& s ) {
^
src/eosio.token.cpp:95:32: error: no member named 'code' in 'eosio::symbol_type'
auto sym = quantity.symbol.code();
~~~~~~~~~~~~~~~ ^
src/eosio.token.cpp:116:52: error: no member named 'code' in 'eosio::symbol_type'
const auto& from = from_acnts.get( value.symbol.code().raw(), "no balance object found" );
~~~~~~~~~~~~ ^
src/eosio.token.cpp:127:42: error: no member named 'code' in 'eosio::symbol_type'
auto to = to_acnts.find( value.symbol.code().raw() );
~~~~~~~~~~~~ ^
src/eosio.token.cpp:133:28: error: use of undeclared identifier 'same_payer'; did you mean 'ram_payer'?
to_acnts.modify( to, same_payer, [&]( auto& a ) {
^~~~~~~~~~
ram_payer
src/eosio.token.cpp:124:56: note: 'ram_payer' declared here
void token::add_balance( name owner, asset value, name ram_payer )
^
src/eosio.token.cpp:139:37: error: unknown type name 'symbol'
void token::open( name owner, const symbol& symbol, name ram_payer )
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.

General stake-weighted voting functionality

Relayed for @jchung00 from EOSIO/eos#5172

Currently, it is difficult to implement stake-weighted voting on any contract. It is possible to find staked amount for each account on the voters table, but it is not possible to track stake/unstake changes within a contract. Therefore, it requires a database off chain that actively monitors delegatebw/undelegatebw actions in order to implement this.

A more general way to allow stake-weight voting to occur fully on chain would be beneficial for some contracts/systems that need it. This includes the Referendum contract and Worker Proposal system. There may also be some other community tools and dApps that need the functionality as well.

A potential solution would be have the system contract send inline-actions for delegatebw/undelegatebw actions, and implementing a general purpose stake based voting scheme in the system contract. Another idea that Greg/Bart mentioned was to add the ability for any contract to "hook" actions in any other contract in the future. For example, a contract that needs stake-weighted voting would "register" with the system contract that it wants an inline action scheduled when someone calls the delegatebw and undelegatebw actions. This solution would allow contracts to build off on existing system contract actions. In order to prevent spam and potential bottleneck, there must be a limit to who can register these "hooks". Therefore, the ability to register could be implemented through an action that requires the permission of eosio.prods, so that only community verified contracts can register the hooks/callback actions.

Update READMEs

In particular the README for eosio.system is out-of-date. Also, the eosio.token README needs additions.

Error in "eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp" command

following tutorial :
https://developers.eos.io/eosio-home/docs/token-contract
in step3 compile the contract by "eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp" encounter errors:

In file included from src/eosio.token.cpp:6:
include/eosio.token/eosio.token.hpp:20:12: warning: unknown attribute 'contract' ignored [-Wunknown-attributes]
   class [[eosio::contract("eosio.token")]] token : public contract {
           ^
include/eosio.token/eosio.token.hpp:41:39: error: unknown type name 'symbol'
         void open( name owner, const symbol& symbol, name ram_payer );
                                      ^
include/eosio.token/eosio.token.hpp:44:40: error: unknown type name 'symbol'
         void close( name owner, const symbol& symbol );
                                       ^
include/eosio.token/eosio.token.hpp:46:64: error: unknown type name 'symbol_code'
         static asset get_supply( name token_contract_account, symbol_code sym_code )
                                                               ^
include/eosio.token/eosio.token.hpp:53:77: error: unknown type name 'symbol_code'
         static asset get_balance( name token_contract_account, name owner, symbol_code sym_code )
                                                                            ^
include/eosio.token/eosio.token.hpp:64:65: error: no member named 'code' in 'eosio::symbol_type'
            uint64_t primary_key()const { return balance.symbol.code().raw(); }
                                                 ~~~~~~~~~~~~~~ ^
include/eosio.token/eosio.token.hpp:72:64: error: no member named 'code' in 'eosio::symbol_type'
            uint64_t primary_key()const { return supply.symbol.code().raw(); }
                                                 ~~~~~~~~~~~~~ ^
src/eosio.token.cpp:20:34: error: no member named 'code' in 'eosio::symbol_type'
    stats statstable( _self, sym.code().raw() );
                             ~~~ ^
src/eosio.token.cpp:21:42: error: no member named 'code' in 'eosio::symbol_type'
    auto existing = statstable.find( sym.code().raw() );
                                     ~~~ ^
src/eosio.token.cpp:38:34: error: no member named 'code' in 'eosio::symbol_type'
    stats statstable( _self, sym.code().raw() );
                             ~~~ ^
src/eosio.token.cpp:39:42: error: no member named 'code' in 'eosio::symbol_type'
    auto existing = statstable.find( sym.code().raw() );
                                     ~~~ ^
src/eosio.token.cpp:50:28: error: use of undeclared identifier 'same_payer'
    statstable.modify( st, same_payer, [&]( auto& s ) {
                           ^
src/eosio.token.cpp:69:34: error: no member named 'code' in 'eosio::symbol_type'
    stats statstable( _self, sym.code().raw() );
                             ~~~ ^
src/eosio.token.cpp:70:42: error: no member named 'code' in 'eosio::symbol_type'
    auto existing = statstable.find( sym.code().raw() );
                                     ~~~ ^
src/eosio.token.cpp:80:28: error: use of undeclared identifier 'same_payer'
    statstable.modify( st, same_payer, [&]( auto& s ) {
                           ^
src/eosio.token.cpp:95:32: error: no member named 'code' in 'eosio::symbol_type'
    auto sym = quantity.symbol.code();
               ~~~~~~~~~~~~~~~ ^
src/eosio.token.cpp:116:52: error: no member named 'code' in 'eosio::symbol_type'
   const auto& from = from_acnts.get( value.symbol.code().raw(), "no balance object found" );
                                      ~~~~~~~~~~~~ ^
src/eosio.token.cpp:127:42: error: no member named 'code' in 'eosio::symbol_type'
   auto to = to_acnts.find( value.symbol.code().raw() );
                            ~~~~~~~~~~~~ ^
src/eosio.token.cpp:133:28: error: use of undeclared identifier 'same_payer'; did you mean 'ram_payer'?
      to_acnts.modify( to, same_payer, [&]( auto& a ) {
                           ^~~~~~~~~~
                           ram_payer
src/eosio.token.cpp:124:56: note: 'ram_payer' declared here
void token::add_balance( name owner, asset value, name ram_payer )
                                                       ^
src/eosio.token.cpp:139:37: error: unknown type name 'symbol'
void token::open( name owner, const symbol& symbol, name ram_payer )
                                    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.

Proposal has a security hole

If A creates an proposal to B to change the owner's own permissions to me, then sells the account to C, which changes the owner's permissions to C. When B executes this proposal, the owner's permissions for the account will be changed to A.

Stake transfer

Please implement the ability to immediately transfer stake between CPU <-> Network
Thanks!

Proxy vote decay

Vote decay is important for the health of the EOS ecosystem. It's also important to have engagement from the community through the proxy option. Unfortunately, the way the code is today a user must re-up their vote to the proxy in order to remain at full voting strength. This defeats the purpose of having a proxy.

Example:

If Bob delegates his token votes to Alice, then Bob is giving Alice the authority to make decisions on Bob's behalf.
If Alice wants to re-up the vote to full strength at the end of the week, Alice shouldn't have to ask Bob to re-up his vote to Alice...as Bob's consent was already given.

I see 2 options for proxies:

  1. No vote decay if you proxy
  2. Vote decay is had, but it's something less than the current 1 week vote decay (perhaps Bob will need to re-up his vote to Alice once every 6 months or else decay begins on 6 months and 1 day).

Looking for feedback on this proposal and what it might take to implement this in a future release.

Need more details how to run testcases

Hi all,
Can you give me more details how to run the testcases?
After building eosio.contracts, this is what I have in build directory:

total 68
drwxr-xr-x 10 root root  4096 Sep 13 08:50 .
drwxr-xr-x 10 root root  4096 Sep 13 08:59 ..
-rw-r--r--  1 root root 14534 Sep 12 21:23 CMakeCache.txt
drwxr-xr-x  5 root root  4096 Sep 13 08:50 CMakeFiles
-rw-r--r--  1 root root  6740 Sep 13 08:50 Makefile
-rw-r--r--  1 root root  1819 Sep 12 21:23 cmake_install.cmake
drwxr-xr-x  4 root root  4096 Sep 12 21:23 contracts_unit_tests-prefix
drwxr-xr-x  3 root root  4096 Sep 13 08:50 eosio.bios
drwxr-xr-x  3 root root  4096 Sep 13 08:50 eosio.msig
drwxr-xr-x  3 root root  4096 Sep 13 08:50 eosio.sudo
drwxr-xr-x  3 root root  4096 Sep 13 08:50 eosio.system
drwxr-xr-x  3 root root  4096 Sep 13 08:50 eosio.token

Now, how can I setup and run testcases. Simply runing command ./tests/unit_test gives this error to me:

Random number generator seeded to 1536804645
Running 78 test cases...
unknown location(0): fatal error: in "eosio_token_tests/create_tests": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(126): last checkpoint: "create_tests" fixture ctor
unknown location(0): fatal error: in "eosio_token_tests/create_negative_max_supply": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(139): last checkpoint: "create_negative_max_supply" fixture ctor
unknown location(0): fatal error: in "eosio_token_tests/symbol_already_exists": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(147): last checkpoint: "symbol_already_exists" fixture ctor
unknown location(0): fatal error: in "eosio_token_tests/create_max_supply": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(164): last checkpoint: "create_max_supply" fixture ctor
unknown location(0): fatal error: in "eosio_token_tests/create_max_decimals": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(188): last checkpoint: "create_max_decimals" fixture ctor
unknown location(0): fatal error: in "eosio_token_tests/issue_tests": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(212): last checkpoint: "issue_tests" fixture ctor
unknown location(0): fatal error: in "eosio_token_tests/retire_tests": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(246): last checkpoint: "retire_tests" fixture ctor
unknown location(0): fatal error: in "eosio_token_tests/transfer_tests": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(303): last checkpoint: "transfer_tests" fixture ctor
unknown location(0): fatal error: in "eosio_token_tests/open_tests": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(349): last checkpoint: "open_tests" fixture ctor
unknown location(0): fatal error: in "eosio_token_tests/close_tests": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.token_tests.cpp(382): last checkpoint: "close_tests" fixture ctor
unknown location(0): fatal error: in "eosio_system_tests/buysell": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.system_tests.cpp(23): last checkpoint: "buysell" fixture ctor
unknown location(0): fatal error: in "eosio_system_tests/stake_unstake": std::runtime_error: locale::facet::_S_create_c_locale name not valid
/root/eosio.contracts/tests/eosio.system_tests.cpp(123): last checkpoint: "stake_unstake" fixture ctor
...

Thanks.

unable to compile in MacOS ( Undefined symbols for architecture x86_64 )

macosx

sh build.sh

getting:

[ 35%] Built target eosio.token.wasm
[ 47%] Performing build step for 'contracts_unit_tests'
[ 52%] Built target eosio.msig.wasm
[ 52%] Built target eosio.sudo.wasm
[ 52%] Built target eosio.system.wasm
[ 16%] Linking CXX executable unit_test
Undefined symbols for architecture x86_64:
"fc::to_variant(fc::crypto::public_key const&, fc::variant&)", referenced from:

...

  eosio_system::eosio_system_tester::setup_producer_accounts(std::__1::vector<eosio::chain::name, std::__1::allocator<eosio::chain::name> > const&) in eosio.system_tests.cpp.o
  ...

ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [unit_test] Error 1
make[4]: *** [CMakeFiles/unit_test.dir/all] Error 2
make[3]: *** [all] Error 2
make[2]: *** [contracts_unit_tests-prefix/src/contracts_unit_tests-stamp/contracts_unit_tests-build] Error 2
make[1]: *** [CMakeFiles/contracts_unit_tests.dir/all] Error 2
make: *** [all] Error 2

Add eosio.token::open action

An open action is needed to complement the existing close action in the eosio.token contract.

Action signature:

void open( account_name owner, symbol_type symbol, account_name ram_payer );

If a table row for that symbol already exists for the owner, then the open action would do nothing. Otherwise, it will create a zero-balance table row for that symbol and charge the RAM to ram_payer.

This action allows contracts or wallet clients to easily replicate the current behavior of eosio.token::transfer even after its behavior is modified (see #62). The current behavior is that the token transfer action succeeds (assuming the sender and recipient contracts that are notified do not fail) even if there is no existing row for that symbol in the recipient's table. Contracts and wallet clients can simply package the two actions (eosio.token::open action followed by the eosio.token::transfer action) and get the same behavior they are used to at the risk of having to pay for the RAM if the recipient's tables need a new table row.

Fix EOSIO dependency version

The latest version of eos is v1.2.3. With this version installed, the build.sh script throws an error:

CMake Error at CMakeLists.txt:9 (message):
  Incorrect EOSIO version, please use version 1.1.x

There's no point in depending on an old version. Please fix it.

eosio.msig approve is subject to TOCTOU race condition

When user approves a multisig proposal there is no hard guarantee that he is approving exactly what he has reviewed.

For instance, someone takes multiple days to review a complex proposal that is changing a smart contract or whatever and approves without double checking that the proposal has not been withdrawn and resubmitted under the same exact name between the review and the approval.

In order to be backward compat, there should be a new approve action with a proposal hash.

REX Implementation

REX Implementation

This issue describes the EOSIO resource exchange (REX) implementation details. For the mathematical details of the Bancor algorithm used in REX, please see this article. In the following, we use SYS to represent the core token of an EOSIO based blockchain.

User REX funds

For REX related actions, a user needs to create a REX fund and deposit SYS tokens into the fund. deposit action, when called for the first time, creates a rex_fund record for the user and sets the balance to the passed SYS amount. Subsequent deposit calls add the passed amount to rex_fund's balance field. An inline token transfer from user's SYS balance is executed. All REX expenses and proceeds are taken out of or added to rex_fund, with one exception being the action unstaketorex which allows buying REX with staked tokens. withdraw action allows a user to take SYS tokens out of rex_fund. An inline token transfer to user's SYS balance is executed.

REX pool balances

REX pool represents the global state of the REX system. It comprises multiple balances:

  • total_lendable is the total SYS value of the REX pool. It's the sum of all payments coming from buying REX actions, all CPU and Network loan fees, and RAM trading fees and name auction proceeds (if these system fees are channeled to REX).
  • total_rex represents the total number of REX tokens. It is incremented (decremented) upon buying (selling) REX. At any point in time, the value of a REX token is given by total_lendable/total_rex. CPU and Network loan payments are added to total_lendable thus increasing the value of a REX token and providing more SYS tokens for renting, and similarly for the system fees mentioned above.
  • total_unlent represents the portion of total_lendable that is available for renting, whereas total_lent represents portion tied in outstanding loans. By definition, total_lendable = total_unlent + total_lent.
  • total_rent is a virtual balance. The initial value of this balance must be strictly positive. This initial value is determined based on an estimate of the expected SYS to be available shortly after deployment, so that renting costs are similar to other markets. The balances total_rent and total_unlent are the two connectors of the Bancor algorithm which determines CPU and Network renting price. The details are available here.

Buying REX with liquid tokens

As the name suggests, the action buyrex allows a user to buy REX tokens in exchange for a provided number of SYS tokens (let's call it payment). It is the action that allows a users lend their SYS tokens. The number of issued REX tokens is calculated such that the ratio total_lendable/total_rex is the same before and after the action is executed. That is, this action leaves the value of a REX token unchanged. A voting requirement is imposed in buyrex: a user must have voted for a proxy or at least 21 producers. payment is added to user's vote stake, and votes of corresponding producers are updated. SYS tokens used for the purchase are taken out of user's rex_fund.

Buying REX with staked tokens

A user can buy REX using staked tokens, without the need for unstaking to liquid tokens first, via unstaketorex action. The action takes as input the staked tokens owner account name (owner), the account name to whom the tokens have been previously staked (receiver), the amount to be unstaked from Network bandwidth (from_net), and the amount to be unstaked from CPU bandwidth (from_cpu). The amount of REX tokens rewarded in return for from_net + from_cpu is calculated the same way as in buyrex. Same voting requirement also applies. owner vote weight is updated to its current value, and from_net and from_cpu are subtracted from the resource limits of receiver.

REX maturities

A delay is imposed on selling REX tokens after they're purchased. Tokens bought cannot be sold until 4 days after end of the day using UTC. Upon multiple purchases, tokens are accumulated into separate maturity buckets represented by rex_maturities field of owner's rex_balance. These buckets hold the amounts that can be sold within less than a day, 2 days, ..., 5 days. The amount of matured REX tokens that can be sold immediately is stored in matured_rex field of rex_balance. Note that this delay is imposed in order to give the renting market time to react. The action consolidate allows the owner to consolidate all maturity buckets (not including REX tokens in the savings bucket described below) and matured REX into one bucket with maturity date of 4 days after the end of the day.

REX savings bucket

In addition to maturity buckets described above, a REX owner can utilize a special bucket which we call the "savings bucket". REX held in this bucket does not mature and cannot be sold directly. Users can move already purchased REX from other buckets to their savings bucket at will using the action mvtosavings. This action moves REX out from the user's buckets as necessary starting with the bucket with furthest maturity date. In order to sell REX in the savings bucket, the user must first explicitly move tokens out of it using the action mvfrsavings which can be executed at any time. The mvfrsavings action moves REX from the savings bucket to a bucket with a maturity date that is 4 days after the end of the day.

Selling REX

sellrex allows user to sell a given number of REX tokens in exchange for SYS. This is equivalent to unlending SYS tokens. If enough SYS tokens are available in total_unlent, the order is processed; otherwise the order is queued until the condition is satisfied. Sell order price is determined at processing time and not order creation time, assuming the two are different. The owner's vote stake is updated to current value of REX tokens held after the order is filled. Using action cnclrexorder, an owner can cancel a queued order any time before it's filled. The proceeds of selling REX are added to owner's rex_fund.

Processing REX sell orders

When a sellrex order can't be filled, it is added to a queue. That is, a rex_order record is created. Its fields are owner which is the unique primary key, rex_requested, order_time, proceeds, stake_change, and is_open. Initially we set rex_requested to REX tokens to be sold, is_open = true, proceeds = 0.0000 SYS, stake_change = 0.0000 SYS, and order_time = current_time_point().
When a rex_order is filled (function fill_rex_order), which can happen because some action provides enough unlent SYS tokens, we set is_open = false, set proceeds to the current exchange price of rex_requested, and calculate the change in vote stake and save it to stake_change. We also update owner's REX balance, rex_balance -= rex_requested, and set vote_stake to current value of rex_balance. rex_pool balances are updated accordingly. The order is then moved to the end of the queue. This is achieved by using a secondary key that is a function of order_time and is_open. The rest of rex_order processing has to be executed in an action pushed by owner. That involves transfering proceeds to owner's rex_fund, updating owner's vote weight by adding stake_change (can be positive or negative) to vote stake (field staked in voter_info), and then deleting the order. That is done by calling function update_rex_account which also updates the votes of corresponding producers.
An owner can have only one open rex_order. If the owner pushes a second sellrex action that can not be filled immediately, the requested REX tokens are added to the rex_requested field of the already existing order.

REX loans

A user can rent CPU and Network resources on behalf of a receiver account using rentcpu and rentnet actions in exchange for a specified SYS payment. These actions create a rex_loan record in cpuloan and netloan tables, respectively. The number of SYS tokens to be added to receiver CPU or Network resources (staked tokens denoted by total_staked field of rex_loan) is calculated from payment using the current market price determined by Bancor algorithm. The two connectors of the algorithm are total_unlent and total_rent. Calculated total_staked is transferred from total_unlent to total_lent, and payment is added to total_rent. After the loan is created, payment is added to REX pool total_lendable and total_unlent thus increasing value of REX token and increasing SYS tokens available for renting. Loan duration is 30 days. At the end of the duration, staked tokens (total_staked) are subtracted from receiver resource limits. total_staked is moved back from total_lent to total_unlent, and total_rent is updated accordingly using Bancor equation.

Loan automatic renewal

In rentnet and rentcpu, a user can provide an additional amount of SYS tokens that are added to the loan's balance field. At expiration, a loan is renewed if it has enough funds, i.e. balance >= payment, otherwise the loan is closed and the user is refunded any tokens remaining in the loan's balance. If a loan is renewed, total_staked is recalculated using current market price and receiver resource limits are updated to reflect that. REX pool balances are updated as well. A loan owner can fund a loan, identified by loan_num, using fundcpuloan or fundnetloan. The owner can also withdraw from a loan's balance using defcpuloan or defnetloan.

REX maintenance

In most REX actions, the function runrex is called. It processes a fixed number (set to 2) of unfilled REX sell orders, expired Network loans, and expired CPU loans. Processing REX orders and loans is described above. Any account can call runrex directly by pushing the rexexec action which takes as input the maximum number (max) of orders, Network loans, and CPU loans to be processed. REX sell orders are given higher priority than loans. Which means that no new loans are created and no existing loans are renewed if rex_order queue is not empty.
The action updaterex updates an owner's vote stake to the current SYS value of their REX balance. It also updates the vote weights of producers that the owner has voted for.
The action closerex deletes an owner's records from REX tables and frees the used RAM. If the owner has a non-zero REX balance, the action fails; otherwise, the owner's rex_balance entry is deleted. If the owner has no outstanding loans and a zero rex_fund balance, rex_fund entry is deleted.

Voting requirements

In order to buy REX, an account must have voted for at least 21 producers or delegated their vote to a proxy. As long as an account holds any REX tokens, the condition must be satisfied.

Block producer greylisting

Would it be possible to implement a feature to greylist / deactivate a block producer when they fail to produce blocks?

If it's detected that a top 21 block producer stops producing blocks, that BP could be flagged as inactive and removed from the top 21 until the situation is remedied.

This is one of the ideas originally tabled in EOSIO/eos#5311

Is it possible to implement this in a smart contract ?

There are A, B, C, and D cards.
I would like to distribute this card at random without knowing each other.

User1: A
User2: B
User3: C
User4: D

The user should not know what his / her other card is
Duplication is not possible.

Is it possible?

Voting Requirements for REX

Voting Requirements

In order to buy REX an account must set and maintain a voting proxy or approve at least 21 block producers. They may change their votes but not remove them while they hold REX tokens. After an account has sold all REX tokens they may vote for less than 21 producers.

Ref: https://medium.com/@bytemaster/proposal-for-eos-resource-renting-rent-distribution-9afe8fb3883a

I'm assuming this will be enforced in the REX smart contract? Will these asserts be located in eosio.system/src/rex.cpp or another module?

eosio.token -- Error 3015004: The type defined in the ABI is invalid

I followed the tutorial: https://developers.eos.io/eosio-home/docs/token-contract.

The contracts seems to be deployed successfully with the command:
cleos set contract eosio.token eosio.token --abi eosio.token.abi -p eosio.token@active

Response:
Reading WASM from eosio.token/eosio.token.wasm...
Publishing contract...
executed transaction: 12948529459321d25366157fb97ba42cc27c51a0a6e25849ccfe4297295e47c5 9696 bytes 15970 us
# eosio <= eosio::setcode {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d0100000001aa011c60037f7e7f0060047f...
# eosio <= eosio::setabi {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e30000605636c6f73650002056f776e6572046e61...

However when I tried to interact with the contract:
cleos push action eosio.token issue '[ "alice", "100.0000 SYS", "memo" ]' -p eosio@active

It came with such error:
Error 3015004: The type defined in the ABI is invalid

The code is cloned yesterday and compiled with:
eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp --abigen

Anyone knows which part goes wrong? Thanks a lot!

ABI file is missing from repo

ABI file is missing. should be a problem but right now cut could not generate correct ABI for eosio.token.

Could we put the manually crafted ABI back or fix the ABI generator for eosio.token?

Contracts needs to self-identify version

Now that the system contracts are no longer part of the base repository, and now that their release version number has diverged from the base software, the contract version in use on any particular chain needs to be identifiable in human-readable form remotely.

Contracts should respond to a version or version_request action.

Give 1400 bytes RAM gift to new accounts

Based on analysis there is a place in EOS code where we charge 2048 bytes for new account. But we use only 576 bytes. So, we could decrease the constant. Instead of that we will give 1400 bytes to every new account in system contract (just to keep native code the same).

Modifications to REX transfers and balance management

  • Create user EOS funds table for REX purposes. User can deposit into and withdraw from his fund using deposit and withdraw actions. Inline token transfer to and from user account is limited to these actions only.
  • Remove inline transfers from all other actions and replace them with a function that updates user's REX fund.
  • Fix unit tests and test new actions.

Some structures of eosio.sytem are outdated

authority structure cannot be used, de-serializetion fails.
eosio.system defines it as:

struct authority {
uint32_t threshold;
uint32_t delay_sec;
std::vector<key_weight> keys;
std::vector<permission_level_weight> accounts;

but eos changed definition to:
https://github.com/EOSIO/eos/blob/905e7c85714aee4286fa180ce946f15ceb4ce73c/libraries/chain/include/eosio/chain/authority.hpp#L73-L76

There are some other outdated structures, as mentioned in EOSIO/eos#4684 and linked issues

can not build with eosio.cdt 1.3.1 from homebrew version

when i run ./build.sh, it shows

  include could not find load file:

    EosioTester


CMake Error at CMakeLists.txt:28 (message):
  Found eosio version but it does not satisfy version requirements: version
  '' is invalid

  Please use eosio version 1.3.x

Add setalimits onto system contract

Relayed for @jchung00 from EOSIO/eos#5174

Currently, there doesn't seem to be a way to grant new accounts in the network unlimited resources (once the system contract has been deployed to eosio). Therefore, new eosio.* accounts such as eosio.sudo and eosio.wps will need tokens to be staked and RAM bought separately.

We've tested that the setpriv action doesn't actually grant an account unlimited resources. Even though the account will show up as privileged, it will still run into problems when not enough tokens are staked and/or insufficient RAM has been bought for the account. (Check screenshot)

screen shot 2018-08-09 at 5 05 30 pm

Accounts such as eosio.token and eosio.names are not privileged. However, they were created by the eosio account during launch, when the eosio was set to the eosio.bios contract. The resource limits for these accounts were set to -1, which gives them unlimited network resources.

In order to allow new community owned eosio.* accounts to receive unlimited network resources, there has to be some action in the system contract that calls the set_resource_limits function. It seems like setalimits actually exists in the abi of the system contract (https://github.com/EOSIO/eos/blob/369c7e31e17630e1327a48869b832635352a27f4/contracts/eosio.system/eosio.system.abi#L506).

However, the action isn't implemented in the system contract-- it is only defined in the eosio.bios contract here: https://github.com/EOSIO/eos/blob/7271924b476fb58c82e2481bb2d06c558bb74215/contracts/eosio.bios/eosio.bios.hpp#L16

Would it make sense to define the setalimits action in the system contract as well (with require_auth(_self);), in order to make it possible for newly created eosio.* accounts to receive unlimited network resources by using eosio permissions?**

Unable to compile contracts

Hi, I am unable to compile eosio.contracts.
I have successfully built eos (v-1.1.0) in the same disk (its an internal disk) and have successfully cloned and build eosio.wasmsdk v1.0.0.
screenshot 2018-07-23 11 08 03

System contract upgrade -- EOS balance row should not be removed even it is zero

replay from @eosbet-io

When a new account is created, the system contract must be updated to create a zero balance entry for eosio.token. Currently, this zero entry is not in the table, so transactions through safetransfer contract are failing because the first EOS transfer into an account needs RAM.

The balance entry for any account in the eosio.token table should never be removed. All past removals need to be added back into the table as well, for the RAM fix to be successful.

50% CW(Bancor connector weight) of RAM market is better than 0.05%

Price-move of EOS/RAM seems same for CW 50% and CW 0.05%.
( #2 , I think CW changes directly have effect on the amount of additionally-issued RAMCORE tokens which is immediately converted(issued/redeemed) between EOS and RAM, not affecting EOS/RAM price changes. )
But if we use CW 50%, we can optimize token conversion operations.

For CW 0.5%, std:pow(xxx, 0.005) and std:pow(xxx, 200) should be calculated,
but for CW 50%, std:pow(xxx, 0.5) and std:pow(xxx, 2) can be optimized to "sqrt()" and "floating point
multiplication" which is way more efficient.
We can modify Bancor token calculation code in eosio.system using more efficient sqrt() and floating point multi. if CW is set to 50% rather than 0.05%

When EOS Smart Contract code is compiled to WebAssembly code(WASM), floating point operations are automatically converted to use 'Soft Float' library to avoid hardware floating point operations which can cause consensus failure among the different machine. So, I think using std:pow is very expensive. Though sqrt() is also involved with many floating point operations, sqrt() is more efficient than pow(xxx,0.5)

I think CW 50% is better option regarding performance optimization.

Use a new metric for producer per-vote pay

A new metric is used for producer per-vote pay. The metric combines vote weight and the time duration a producer has held the vote.

A producer's share (call it vs) of the per-vote bucket is calculated as follows:

  • vs is is initially set to zero.
  • At time vt1 a voter votes for the producer with weight w1. vs stays zero.
  • Later, at time vt2 a second voter votes for the producer with weight w2. At this point, vs is updated to vs = w1 * (vt2 - vt1).
  • At later time, vt3, a third voter votes for the producer. Update vs to vs = w1 * (vt2 - vt1) + (w1 + w2) * (vt3 - vt2).
  • When the producer claimrewards at time ct, update vs to vs = w1 * (vt2 - vt1) + (w1 + w2) * (vt3 - vt2) + (w1 + w2 + w3) * (ct - vt3).
  • Producer's per-vote pay is then calculated as (vs * per-vote-bucket) / (total vs of all producers).
  • After a producer claimrewards, his share vs is set to zero.

A producer who carries some votes, can have his vote-pay share increase with time if he doesn't claimrewards. In a sense vote-pay share can increase due to inactivity. To avoid that, we don't update vote-pay share of producers who haven't claimrewards in the past 3 days when a voter votes or updates his stake.

eosio.msig can undo account transfers.

Problem

There are currently two competing EOS account exchanges live:
https://www.eosnameswaps.com
https://eoscontract.io/exchangename

As documented here,https://medium.com/@motchamotcha/eosio-multisig-contract-vulnerability-b5289d18223f, both dApps are vunerable to unexecuted eosio.msig proposal/approvals that restore an accounts permission after it has been transferred to a new user.

It is currently possible to check the eosio.msig tables for proposal/approvals by the account in question. It is not possible to check whether a proposal that affects the permission of an account has been proposed by a different account. There is therefore no guaranteed in-contract method for transferring accounts. Other applications, such as account lending and ram shorting, can also not be developed.

Possible Solution

Modify eosio.msig to emplace the account name that is being affected by an msig action into a table that can be searched.

Note: There is similar vunerability with deferred transactions.

Linking CXX executable unit_test -> undefined reference error

Hi guys,

I;m getting the following issue:

[ 82%] Linking CXX executable eosio.system.wasm
[ 82%] Built target eosio.system.wasm
[100%] Linking CXX executable unit_test
CMakeFiles/unit_test.dir/eosio.msig_tests.cpp.o: In function eosio_msig_tests::propose_approve_execute::test_method()': **/home/jj/tmp/eosio.contracts/tests/eosio.msig_tests.cpp:(.text+0x1790): undefined reference to eosio::testing::base_tester::abi_serializer_max_time'**
CMakeFiles/unit_test.dir/eosio.msig_tests.cpp.o: In function eosio_msig_tests::propose_approve_unapprove::test_method()': /home/jj/tmp/eosio.contracts/tests/eosio.msig_tests.cpp:(.text+0x5210): undefined reference to eosio::testing::base_tester::abi_serializer_max_time'
CMakeFiles/unit_test.dir/eosio.msig_tests.cpp.o: In function eosio_msig_tests::propose_approve_by_two::test_method()': /home/jj/tmp/eosio.contracts/tests/eosio.msig_tests.cpp:(.text+0x861e): undefined reference to eosio::testing::base_tester::abi_serializer_max_time'
CMakeFiles/unit_test.dir/eosio.msig_tests.cpp.o: In function eosio_msig_tests::propose_with_wrong_requested_auth::test_method()': /home/jj/tmp/eosio.contracts/tests/eosio.msig_tests.cpp:(.text+0xc42e): undefined reference to eosio::testing::base_tester::abi_serializer_max_time'
CMakeFiles/unit_test.dir/eosio.msig_tests.cpp.o: In function eosio_msig_tests::big_transaction::test_method()': /home/jj/tmp/eosio.contracts/tests/eosio.msig_tests.cpp:(.text+0xf7d7): undefined reference to eosio::testing::base_tester::abi_serializer_max_time'
CMakeFiles/unit_test.dir/eosio.msig_tests.cpp.o:/home/jj/tmp/eosio.contracts/tests/eosio.msig_tests.cpp:(.text+0x157c2): more undefined references to eosio::testing::base_tester::abi_serializer_max_time' follow CMakeFiles/unit_test.dir/eosio.msig_tests.cpp.o: In function eosio::testing::contracts::util::exchange_wasm()':
/home/jj/tmp/eosio.contracts/tests/eosio.msig_tests.cpp:(.text._ZN5eosio7testing9contracts4util13exchange_wasmEv[_ZN5eosio7testing9contracts4util13exchange_wasmEv]+0x1a): undefined reference to `eosio::testing::read_wasm(char const*)'

Environment: Ubuntu 16.04

Regards,
jj

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.