Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contract auth #598

Merged
merged 33 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
15edd8b
contract auth
tbfleming Nov 4, 2021
b7257c2
contract auth
tbfleming Nov 4, 2021
4716d5a
contract auth
tbfleming Nov 4, 2021
83dcd2c
contract auth
tbfleming Nov 4, 2021
e77b07e
Merge remote-tracking branch 'origin/main' into contract-auth
tbfleming Nov 5, 2021
2cfac49
contract auth
tbfleming Nov 5, 2021
5459062
contract auth
tbfleming Nov 5, 2021
03ecc68
contract auth
tbfleming Nov 5, 2021
301177f
contract auth
tbfleming Nov 6, 2021
a4462a6
Merge remote-tracking branch 'origin/main' into contract-auth
tbfleming Nov 6, 2021
c390977
contract auth
tbfleming Nov 6, 2021
108cd32
contract auth
tbfleming Nov 9, 2021
37041ba
contract auth
tbfleming Nov 9, 2021
520a764
contract auth
tbfleming Nov 9, 2021
f45c09d
Merge remote-tracking branch 'origin/main' into contract-auth
tbfleming Nov 10, 2021
4813981
contract auth
tbfleming Nov 10, 2021
97a1508
cleanup
tbfleming Nov 10, 2021
5677922
cleanup
tbfleming Nov 10, 2021
8e4b859
cleanup
tbfleming Nov 10, 2021
684d629
cleanup
tbfleming Nov 10, 2021
ce4b250
Merge remote-tracking branch 'origin/main' into contract-auth
tbfleming Nov 11, 2021
b1ec81a
sessions
tbfleming Nov 12, 2021
45c22d8
Merge remote-tracking branch 'origin/main' into contract-auth
tbfleming Nov 15, 2021
479bbde
sessions
tbfleming Nov 15, 2021
aa1c8bc
address feedback
tbfleming Nov 18, 2021
3ff60f6
bug fix
tbfleming Nov 24, 2021
869a544
Merge remote-tracking branch 'origin/main' into contract-auth
tbfleming Nov 24, 2021
08ff926
address feedback
tbfleming Nov 24, 2021
b46a8b9
switch crypto key data to unsigned
tbfleming Nov 24, 2021
e028ee6
extensible auth
tbfleming Nov 25, 2021
0a7c729
Merge remote-tracking branch 'origin/main' into contract-auth
tbfleming Nov 30, 2021
fea0b76
no_auth
tbfleming Nov 30, 2021
c58bb0a
contract auth
tbfleming Nov 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/eden/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_executable(eden
src/actions/migrate.cpp
src/actions/encrypt.cpp
src/actions/tables.cpp
src/actions/sessions.cpp
src/eden.cpp
src/events.cpp
src/accounts.cpp
Expand Down
118 changes: 88 additions & 30 deletions contracts/eden/include/eden.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#include <constants.hpp>
#include <eden-atomicassets.hpp>
#include <eden_dispatcher.hpp>
#include <encrypt.hpp>
#include <eosio/asset.hpp>
#include <eosio/bytes.hpp>
#include <eosio/eosio.hpp>
#include <inductions.hpp>
#include <sessions.hpp>
#include <string>
#include <vector>

Expand Down Expand Up @@ -40,6 +42,9 @@ namespace eden
extern const char* peacetreaty_clause;
extern const char* bylaws_clause;

// Placeholder; the ABI generator redefines this
using action = std::variant<int>;

#ifdef ENABLE_SET_TABLE_ROWS
using table_variant = boost::mp11::mp_append<account_variant,
auction_variant,
Expand Down Expand Up @@ -74,6 +79,20 @@ namespace eden
const eosio::asset& quantity,
std::string memo);

void newsession(eosio::name eden_account,
const eosio::public_key& key,
eosio::block_timestamp expiration,
const std::string& description);

void delsession(const eosio::excluded_arg<session_info>& current_session,
eosio::name eden_account,
const eosio::public_key& key);

void execsession(const eosio::signature& signature,
eosio::ignore<eosio::name> eden_account,
eosio::ignore<eosio::varuint32> sequence,
eosio::ignore<std::vector<action>> actions);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this interface much

  • The requirement of assigning unique sequential integers to the actions is ugly
  • It doesn't allow authorization actions on a different contract, which could become a problem if we do need to put functionality into a separate contract. I'd prefer to see std::vector<eosio::action> or even eosio::transaction
  • The fact that there is one action that can behave the same as many other actions makes filtering harder. Ideally, I'd like to see this run the other actions as inline actions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we come up with an alternative, I don't want it to sacrifice the ability of existing history tools to create a human-readable decoding of the original request. Right now they can use ABI decoding to show what's in the action vector.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For history purposes,I don't see why it's important that the original request is human readable vs. having a human readable decoding in the trace. Having the original request human readable is normally critical for signing, but that's not an issue here.

Copy link
Collaborator

@sparkplug0025 sparkplug0025 Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a human readable decoding in the trace

I like this too, starting to look good... but still hard to digest in block explorer (needs to open the transactions first and then look for traces)


void withdraw(eosio::name owner, const eosio::asset& quantity);

void donate(eosio::name payer, const eosio::asset& quantity);
Expand All @@ -95,21 +114,33 @@ namespace eden

void clearall();

void inductinit(uint64_t id,
void inductinit(const eosio::excluded_arg<session_info>& current_session,
uint64_t id,
eosio::name inviter,
eosio::name invitee,
std::vector<eosio::name> witnesses);

void inductprofil(uint64_t id, new_member_profile new_member_profile);
void inductprofil(const eosio::excluded_arg<session_info>& current_session,
uint64_t id,
new_member_profile new_member_profile);

void inductvideo(eosio::name account, uint64_t id, std::string video);
void inductvideo(const eosio::excluded_arg<session_info>& current_session,
eosio::name account,
uint64_t id,
std::string video);

void inductendors(eosio::name account, uint64_t id, eosio::checksum256 induction_data_hash);
void inductendors(const eosio::excluded_arg<session_info>& current_session,
eosio::name account,
uint64_t id,
eosio::checksum256 induction_data_hash);

void inductdonate(eosio::name payer, uint64_t id, const eosio::asset& quantity);

void inductcancel(eosio::name account, uint64_t id);
void inductmeetin(eosio::name account,
void inductcancel(const eosio::excluded_arg<session_info>& current_session,
eosio::name account,
uint64_t id);
void inductmeetin(const eosio::excluded_arg<session_info>& current_session,
eosio::name account,
uint64_t id,
const std::vector<encrypted_key>& keys,
const eosio::bytes& data,
Expand All @@ -127,16 +158,25 @@ namespace eden
const std::string& election_time,
uint32_t round_duration_sec);

void electopt(eosio::name member, bool participating);
void electopt(const eosio::excluded_arg<session_info>& current_session,
eosio::name member,
bool participating);

void electseed(const eosio::bytes& btc_header);
void electmeeting(eosio::name account,
void electmeeting(const eosio::excluded_arg<session_info>& current_session,
eosio::name account,
uint8_t round,
const std::vector<encrypted_key>& keys,
const eosio::bytes& data,
const std::optional<eosio::bytes>& old_data);
void electvote(uint8_t round, eosio::name voter, eosio::name candidate);
void electvideo(uint8_t round, eosio::name voter, const std::string& video);
void electvote(const eosio::excluded_arg<session_info>& current_session,
uint8_t round,
eosio::name voter,
eosio::name candidate);
void electvideo(const eosio::excluded_arg<session_info>& current_session,
uint8_t round,
eosio::name voter,
const std::string& video);
void electprocess(uint32_t max_steps);

void distribute(uint32_t max_steps);
Expand Down Expand Up @@ -188,9 +228,12 @@ namespace eden
eosio::ignore<std::vector<eosio::asset>>);
};

EOSIO_ACTIONS(
EDEN_ACTIONS(
eden,
"eden.gm"_n,
action(newsession, eden_account, key, expiration, description),
eden_session_action(delsession, 0, eden_account, key),
action(execsession, sig, eden_account, sequence, actions),
action(withdraw, owner, quantity, ricardian_contract(withdraw_ricardian)),
action(donate, owner, quantity),
action(fundtransfer, from, distribution_time, rank, to, amount, memo),
Expand All @@ -211,35 +254,50 @@ namespace eden
action(addtogenesis, account, expiration),
action(gensetexpire, id, new_expiration),
action(clearall, ricardian_contract(clearall_ricardian)),
action(inductinit,
id,
inviter,
invitee,
witnesses,
ricardian_contract(inductinit_ricardian)),
action(inductmeetin, account, id, keys, data, old_data),
action(inductprofil, id, new_member_profile, ricardian_contract(inductprofil_ricardian)),
action(inductvideo, account, id, video, ricardian_contract(inductvideo_ricardian)),
action(inductendors,
account,
id,
induction_data_hash,
ricardian_contract(inductendors_ricardian)),
eden_session_action(inductinit,
10,
id,
inviter,
invitee,
witnesses,
ricardian_contract(inductinit_ricardian)),
eden_session_action(inductmeetin, 1, account, id, keys, data, old_data),
eden_session_action(inductprofil,
2,
id,
new_member_profile,
ricardian_contract(inductprofil_ricardian)),
eden_session_action(inductvideo,
3,
account,
id,
video,
ricardian_contract(inductvideo_ricardian)),
eden_session_action(inductendors,
4,
account,
id,
induction_data_hash,
ricardian_contract(inductendors_ricardian)),
action(setencpubkey, account, key),
action(electsettime, election_time),
action(electconfig, day, time, round_duration),
action(electopt, member, participating),
eden_session_action(electopt, 5, member, participating),
action(electseed, btc_header),
action(electmeeting, account, round, keys, data, old_data),
action(electvote, round, voter, candidate),
action(electvideo, round, voter, video),
eden_session_action(electmeeting, 6, account, round, keys, data, old_data),
eden_session_action(electvote, 7, round, voter, candidate),
eden_session_action(electvideo, 8, round, voter, video),
action(electprocess, max_steps),
action(bylawspropose, proposer, bylaws),
action(bylawsapprove, approver, bylaws_hash),
action(bylawsratify, approver, bylaws_hash),
action(distribute, max_steps),
action(inductdonate, payer, id, quantity, ricardian_contract(inductdonate_ricardian)),
action(inductcancel, account, id, ricardian_contract(inductcancel_ricardian)),
eden_session_action(inductcancel,
9,
account,
id,
ricardian_contract(inductcancel_ricardian)),
action(inducted, inductee, ricardian_contract(inducted_ricardian)),
action(resign, account),
action(gc, limit, ricardian_contract(gc_ricardian)),
Expand Down
20 changes: 20 additions & 0 deletions contracts/eden/include/eden_abi_generator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#define EOSIO_ABIGEN_ITEMeden_session_actions(ns, variant_name, missing_struct_name) \
([&] { \
gen.def.structs.push_back(eosio::struct_def{missing_struct_name}); \
eosio::variant_def vdef{variant_name}; \
ns::for_each_session_action([&](uint32_t index, const char* name, const auto&) { \
if (index >= vdef.types.size()) \
vdef.types.resize(index + 1, missing_struct_name); \
vdef.types[index] = name; \
}); \
auto& variants = gen.def.variants.value; \
auto it = std::find_if(variants.begin(), variants.end(), \
[&](auto& d) { return d.name == variant_name; }); \
if (it != variants.end()) \
*it = std::move(vdef); \
else \
variants.push_back(std::move(vdef)); \
})(); \
, 1
108 changes: 108 additions & 0 deletions contracts/eden/include/eden_dispatcher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#pragma once

#include <eosio/dispatcher.hpp>
#include <sessions.hpp>

namespace eden
{
template <typename T, typename R, typename... Args>
void execute_session_action(
eosio::name contract,
R (T::*func)(const eosio::excluded_arg<session_info>& current_session, Args...),
const eosio::excluded_arg<session_info>& current_session,
eosio::datastream<const char*>& ds)
{
std::tuple<std::remove_cvref_t<Args>...> t;
ds >> t;
T inst(contract, contract, ds);
std::apply([&](auto&... args) { (inst.*func)(current_session, std::move(args)...); }, t);
}
} // namespace eden

#define EOSIO_MATCH_ACTIONeden_session_action EOSIO_MATCH_YES
#define EOSIO_EXTRACT_ACTION_NAMEeden_session_action(name, index, ...) name
#define EOSIO_EXTRACT_ACTION_ARGSeden_session_action(name, index, ...) __VA_ARGS__

#define EDEN_MATCH_SESSION_ACTION(x) EOSIO_MATCH(EDEN_MATCH_SESSION_ACTION, x)
#define EDEN_MATCH_SESSION_ACTIONeden_session_action EOSIO_MATCH_YES

#define EDEN_EXTRACT_SESSION_ACTION_INDEX(x) BOOST_PP_CAT(EDEN_EXTRACT_SESSION_ACTION_INDEX, x)
#define EDEN_EXTRACT_SESSION_ACTION_INDEXeden_session_action(name, index, ...) index

#define EDEN_DISPATCH_SESSION_ACTION_INTERNAL_1(r, type, member) \
case EDEN_EXTRACT_SESSION_ACTION_INDEX(member): \
::eden::execute_session_action(contract, &type::EOSIO_EXTRACT_ACTION_NAME(member), \
current_session, ds); \
return true;
#define EDEN_DISPATCH_SESSION_ACTION_INTERNAL(r, type, member) \
BOOST_PP_IIF(EDEN_MATCH_SESSION_ACTION(member), EDEN_DISPATCH_SESSION_ACTION_INTERNAL_1, \
EOSIO_EMPTY) \
(r, type, member)
#define EDEN_DISPATCH_SESSION_ACTION(type, MEMBERS) \
BOOST_PP_SEQ_FOR_EACH(EDEN_DISPATCH_SESSION_ACTION_INTERNAL, type, MEMBERS)

#define EDEN_GET_SESSION_ACTION_INTERNAL_1(r, type, member) \
f(EDEN_EXTRACT_SESSION_ACTION_INDEX(member), \
BOOST_PP_STRINGIZE(EOSIO_EXTRACT_ACTION_NAME(member)), \
&type::EOSIO_EXTRACT_ACTION_NAME(member));
#define EDEN_GET_SESSION_ACTION_INTERNAL(r, type, member) \
BOOST_PP_IIF(EDEN_MATCH_SESSION_ACTION(member), EDEN_GET_SESSION_ACTION_INTERNAL_1, \
EOSIO_EMPTY) \
(r, type, member)
#define EDEN_GET_SESSION_ACTION(type, MEMBERS) \
BOOST_PP_SEQ_FOR_EACH(EDEN_GET_SESSION_ACTION_INTERNAL, type, MEMBERS)

#define EDEN_NAME_FOR_SESSION_ACTION_INTERNAL_1(r, type, member) \
case EDEN_EXTRACT_SESSION_ACTION_INDEX(member): \
return BOOST_PP_CAT(BOOST_PP_STRINGIZE(EOSIO_EXTRACT_ACTION_NAME(member)), _n);
#define EDEN_NAME_FOR_SESSION_ACTION_INTERNAL(r, type, member) \
BOOST_PP_IIF(EDEN_MATCH_SESSION_ACTION(member), EDEN_NAME_FOR_SESSION_ACTION_INTERNAL_1, \
EOSIO_EMPTY) \
(r, type, member)
#define EDEN_NAME_FOR_SESSION_ACTION(type, MEMBERS) \
BOOST_PP_SEQ_FOR_EACH(EDEN_NAME_FOR_SESSION_ACTION_INTERNAL, type, MEMBERS)

#define EDEN_INDEX_FOR_SESSION_ACTION_INTERNAL_1(r, type, member) \
if (name == BOOST_PP_CAT(BOOST_PP_STRINGIZE(EOSIO_EXTRACT_ACTION_NAME(member)), _n)) \
return EDEN_EXTRACT_SESSION_ACTION_INDEX(member);
#define EDEN_INDEX_FOR_SESSION_ACTION_INTERNAL(r, type, member) \
BOOST_PP_IIF(EDEN_MATCH_SESSION_ACTION(member), EDEN_INDEX_FOR_SESSION_ACTION_INTERNAL_1, \
EOSIO_EMPTY) \
(r, type, member)
#define EDEN_INDEX_FOR_SESSION_ACTION(type, MEMBERS) \
BOOST_PP_SEQ_FOR_EACH(EDEN_INDEX_FOR_SESSION_ACTION_INTERNAL, type, MEMBERS)

#define EDEN_ACTIONS(CONTRACT_CLASS, CONTRACT_ACCOUNT, ...) \
EOSIO_ACTIONS(CONTRACT_CLASS, CONTRACT_ACCOUNT, __VA_ARGS__) \
namespace actions \
{ \
inline bool session_dispatch(eosio::name contract, \
uint32_t index, \
const eosio::excluded_arg<session_info>& current_session, \
eosio::datastream<const char*>& ds) \
{ \
switch (index) \
{ \
EDEN_DISPATCH_SESSION_ACTION(CONTRACT_CLASS, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
} \
return false; \
} \
template <typename F> \
void for_each_session_action(F f) \
{ \
EDEN_GET_SESSION_ACTION(CONTRACT_CLASS, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
} \
inline eosio::name get_name_for_session_action(uint32_t index) \
{ \
switch (index) \
{ \
EDEN_NAME_FOR_SESSION_ACTION(CONTRACT_CLASS, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
} \
return {}; \
} \
inline std::optional<uint32_t> get_index_for_session_action(eosio::name name) \
{ \
EDEN_INDEX_FOR_SESSION_ACTION(CONTRACT_CLASS, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
return {}; \
} \
}
23 changes: 22 additions & 1 deletion contracts/eden/include/events.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <eosio/asset.hpp>
#include <eosio/crypto.hpp>
#include <eosio/fixed_bytes.hpp>
#include <eosio/name.hpp>
#include <eosio/reflection.hpp>
Expand Down Expand Up @@ -206,6 +207,24 @@ namespace eden
};
EOSIO_REFLECT(distribution_event_return, owner, distribution_time, rank, amount, pool)

// Session events

struct session_new_event
{
eosio::name eden_account;
eosio::public_key key;
eosio::block_timestamp expiration;
std::string description;
};
EOSIO_REFLECT(session_new_event, eden_account, key, expiration, description)

struct session_del_event
{
eosio::name eden_account;
eosio::public_key key;
};
EOSIO_REFLECT(session_del_event, eden_account, key)

using event = std::variant<election_event_schedule,
election_event_begin,
election_event_seeding,
Expand All @@ -225,7 +244,9 @@ namespace eden
distribution_event_return_excess,
distribution_event_fund,
distribution_event_end,
distribution_event_return>;
distribution_event_return,
session_new_event,
session_del_event>;

void push_event(const event& e, eosio::name self);
void send_events(eosio::name self);
Expand Down
Loading