Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Enforce read-only nature of an action with read-only attribute #1068

Merged
merged 37 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a46cde2
add testing smart contract for read-only query
bogniq Feb 26, 2021
2839f32
add FunctionDecl visitor
bogniq Mar 9, 2021
0c305e5
Add read only query test contract as a part of read only query TDD.
softprofe Mar 10, 2021
51233fd
Add host functions test actions. not finished, continue next week
softprofe Mar 13, 2021
2abede0
Add test action for some host functions
softprofe Mar 16, 2021
f3c7af6
add implementation for read-only checking
bogniq Mar 16, 2021
0d0d176
add checking for extern c function
bogniq Mar 19, 2021
70b08b6
fix if condition for process_function
bogniq Mar 22, 2021
b231e24
add option -warn-action-read-only
bogniq Mar 24, 2021
439bb39
Add test case for inline host functions.
softprofe Mar 25, 2021
52cebae
Add alias test for host functions
softprofe Mar 25, 2021
3502972
add support for CDT_WARN/ERROR in codegen
bogniq Mar 29, 2021
087fa9b
Add two more chained indirect call test actions
softprofe Mar 30, 2021
602b057
set git branch for submodule eosio_llvm
bogniq Mar 30, 2021
c99f002
add more checkings; clean up code
bogniq Mar 31, 2021
486c04e
update commit hash for submodule eosio_llvm
bogniq Apr 1, 2021
529e50b
Merge branch 'develop' into qy-read-only-action
bogniq Apr 1, 2021
7544797
Move test contract files so as to easily used by team.
softprofe Apr 1, 2021
17c82b0
Merge remote-tracking branch 'origin/keke_epe748' into qy-read-only-a…
bogniq Apr 2, 2021
9314f35
add toolchain tests
bogniq Apr 2, 2021
2818077
Change flag to read_only for get() action
softprofe Apr 2, 2021
e96c14e
Merge remote-tracking branch 'origin/keke_epe748' into qy-read-only-a…
bogniq Apr 2, 2021
4ff7792
add regex support for toolchain tester; fix string compare
bogniq Apr 6, 2021
ec018c2
Using get_self instead of "eosio"_n so as to decouple tables with "eo…
softprofe Apr 7, 2021
3c77cf7
Merge remote-tracking branch 'origin/keke_epe748' into qy-read-only-a…
bogniq Apr 7, 2021
5b9b142
Merge branch 'develop' into qy-read-only-action
bogniq Apr 12, 2021
3bcf551
check local function pointers
bogniq Apr 19, 2021
61a24c0
fix read-only action calling issue
bogniq Apr 19, 2021
d8a16d3
Merge branch 'develop' into qy-read-only-action
bogniq Apr 19, 2021
17a0a29
check global function pointer for write function
bogniq Apr 22, 2021
e4beb61
check class data members for write funciton
bogniq Apr 26, 2021
add76f9
fix function pointer reassignment
bogniq Apr 26, 2021
f5cef84
code clean-up for different statement types
bogniq Apr 29, 2021
0edea87
add support for multiple declarations; clean up code
bogniq May 10, 2021
69f6916
Merge branch 'develop' into qy-read-only-action
bogniq May 18, 2021
ef00c9d
remove system header checking; use C name to find write host function
bogniq May 21, 2021
bf9c37a
change llvm branch to eosio
bogniq May 24, 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 .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[submodule "eosio_llvm"]
path = eosio_llvm
url = https://github.com/eosio/llvm
branch = eosio
[submodule "libraries/native/softfloat"]
path = libraries/native/softfloat
url = https://github.com/EOSIO/berkeley-softfloat-3.git
2 changes: 1 addition & 1 deletion eosio_llvm
Submodule eosio_llvm updated 2 files
+1 −0 .gitmodules
+1 −1 tools/clang
251 changes: 251 additions & 0 deletions tests/toolchain/compile-fail/hf_indirect_call_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
#include <eosio/eosio.hpp>
#include <eosio/table.hpp>
#include <eosio/contract.hpp>
#include <eosio/action.hpp>
#include <eosio/crypto.hpp>
#include <eosio/fixed_bytes.hpp>
#include <eosio/privileged.hpp>
#include <eosio/producer_schedule.hpp>

#include <eosio/asset.hpp>
#include <eosio/binary_extension.hpp>
#include <eosio/singleton.hpp>
#include <eosio/system.hpp>
#include <eosio/time.hpp>
/*
tests which create aliases and indirect calls for host functions.
at least one host function called within a C++ lambda. It can be a trivial lambda which simply calls the host function and nothing else.
at least one host function "renamed" with a using directive and called via the alternative name.
at least one host function "renamed" with a #define and called using that alternative name.
Possibly in two different versions, one which #defines just the function name and one which #defines both the function name and the parameters passed to it.
Yes, both versions I think. It may not be functionally different to the compiler but it looks different to a human, so let's try it.
And finally, combine all four in a chain of aliases
*/

extern "C" __attribute__((eosio_wasm_import)) void set_resource_limit(int64_t, int64_t, int64_t);
extern "C" __attribute__((eosio_wasm_import)) void foo_bar(int64_t, int64_t, int64_t);

#define ACTION_TYPE [[eosio::action, eosio::read_only]]

using func = void (*)(int64_t, int64_t, int64_t);

func srl_g1 = set_resource_limit;
func srl_g2 = set_resource_limit;
func srl_g3;
func fb_g = foo_bar;

class [[eosio::contract]] hf_indirect_call_tests : public eosio::contract {
public:
using contract::contract;
func srl_m1 = set_resource_limit;
func srl_m2 = set_resource_limit;
func srl_m3;
func fb_m = foo_bar;

ACTION_TYPE
bool tlambda() {
auto set_rsc = [](){
set_resource_limit(0, 0, 0);
};
set_rsc();
return true;
}

ACTION_TYPE
bool tlambdap() {
auto set_rsc = [](int64_t a, int64_t b, int64_t c){
set_resource_limit(a, b, c);
};
set_rsc(0, 0, 0);
return true;
}

ACTION_TYPE
bool tlambdap2(int64_t a, int64_t b, int64_t c) {
auto set_rsc = [=](int64_t x, int64_t y, int64_t z){
set_resource_limit(x, y, z);
};
set_rsc(a, b, c);
return true;
}

ACTION_TYPE
bool talias () {
func srl = set_resource_limit;
srl(0,0,0);
return true;
}

ACTION_TYPE
bool taliasg1() {
srl_g1(0,0,0);
return true;
}

ACTION_TYPE
bool taliasg2 () {
srl_g2 = foo_bar;
srl_g2(0,0,0);
return true;
}

ACTION_TYPE
bool taliasg3 () {
srl_g3 = set_resource_limit;
srl_g3(0,0,0);
return true;
}

ACTION_TYPE
bool taliasg3re1 () {
srl_g3 = foo_bar;
srl_g3(0,0,0);
srl_g3 = set_resource_limit;
srl_g3(0,0,0);
return true;
}

ACTION_TYPE
bool taliasg3re2 () {
srl_g3 = set_resource_limit;
srl_g3 = foo_bar;
srl_g3(0,0,0);
return true;
}

ACTION_TYPE
bool taliasg3re3 () {
srl_g3 = foo_bar;
srl_g3 = set_resource_limit;
srl_g3(0,0,0);
return true;
}

ACTION_TYPE
bool taliasgr () {
fb_g(0,0,0);
return true;
}

ACTION_TYPE
bool taliasm1 () {
srl_m1(0,0,0);
return true;
}

ACTION_TYPE
bool taliasm2 () {
srl_m2 = foo_bar;
srl_m2(0,0,0);
return true;
}

ACTION_TYPE
bool taliasm3 () {
srl_m3 = set_resource_limit;
srl_m3(0,0,0);
return true;
}

ACTION_TYPE
bool taliasm3re1 () {
srl_m3 = foo_bar;
srl_m3(0,0,0);
srl_m3 = set_resource_limit;
srl_m3(0,0,0);
return true;
}

ACTION_TYPE
bool taliasm3re2 () {
srl_m3 = set_resource_limit;
srl_m3 = foo_bar;
srl_m3(0,0,0);
return true;
}

ACTION_TYPE
bool taliasm3re3 () {
srl_m3 = foo_bar;
srl_m3 = set_resource_limit;
srl_m3(0,0,0);
return true;
}

ACTION_TYPE
bool taliasmr () {
fb_m(0,0,0);
return true;
}

ACTION_TYPE
bool taliasma () {
func srl_a1, srl_a2 = set_resource_limit;
srl_a2(0,0,0);
}

#define setfun set_resource_limit
ACTION_TYPE
bool tdefine(){
setfun(0,0,0);
return true;
}

#define setfunp() set_resource_limit(0,0,0)
ACTION_TYPE
bool tdefinep(){
setfunp();
return true;
}

#define setfunpi(a, b, c) set_resource_limit(a,b,c)
ACTION_TYPE
bool tdefinepi(){
setfunpi(0,0,0);
return true;
}

ACTION_TYPE
bool combine(){
func srl = set_resource_limit;
srl(0,0,0);
setfun(0,0,0);
setfunp();
setfunpi(0,0,0);
return true;
}

ACTION_TYPE
bool combinea(){
tlambdap();
tlambdap2(0,0,0);
talias();
tdefine();
tdefinep();
tdefinepi();
combine();
return true;
}

ACTION_TYPE
bool combinec(){
auto set_rsc = [](){
func _srl = set_resource_limit;
#define mysrl _srl
mysrl(0, 0, 0);
};
set_rsc();
return true;
}

ACTION_TYPE
bool combinecp(){
auto set_rsc = [](int64_t a, int64_t b, int64_t c){
func _srl = set_resource_limit;
#define mysrl _srl
mysrl(a, b, c);
};
set_rsc(0,0,0);
return true;
}
};
11 changes: 11 additions & 0 deletions tests/toolchain/compile-fail/hf_indirect_call_tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"tests" : [
{
"compile_flags": [],
"expected" : {
"exit-code": 255,
"stderr": "(codegen error.*){20}"
}
}
]
}
Loading