GithubHelp home page GithubHelp logo

samplesforarticle's Introduction

Samples for medium article

eos is avaliable here : https://github.com/EOSIO/eos

eosio.cdt (building contract) is avaliable here : https://github.com/EOSIO/eosio.cdt

wasm2c is avaliable here : https://github.com/WebAssembly/wabt

initialization: init.sh

sources for contracts:

ContractB.cpp

ContractC.cpp

ContractD.cpp

ContractGame2.cpp

ContractGame2.cpp

time line of transactions after init here: commands.sh

decompilation info in folder

./decompile

decompiled.c - file with full contract game2 decompilation

decompiled_short.c contains only decompilation of

extern "C" {
	uint64_t get_rand() {
		return (now() + tapos_block_prefix()) * 179424691u % 0x0fedcba7afffffff; //some magic values
	}
	void apply(uint64_t receiver, uint64_t code, uint64_t action) {
		auto x = get_rand();
		print(x);
	}
}

Random in decompiled.c code:

j0 = (*Z_envZ_current_timeZ_jv)(); // Here we've got current_time
l14 = j0;
i0 = (*Z_envZ_tapos_block_prefixZ_iv)(); // Here we've got tapos_block_prefix
l6 = i0;
i0 = 8619u;
(*Z_envZ_printsZ_vi)(i0); // some debug print
i0 = l6;
j1 = l14;
j2 = 1000000ull;
j1 = DIV_U(j1, j2); //here we got now (c_t /= 1000000)
i1 = (u32)(j1);
i0 += i1; //heere's their sum
i1 = 179424691u;
i0 *= i1; //here's our random seed
i1 = 100u;
i0 = REM_U(i0, i1); // here's our roll

The same in decompiled_short.c:

u64 l3 = 0;
FUNC_PROLOGUE;
u32 i0, i1;
u64 j0, j1, j2;
f8();
j0 = (*Z_envZ_current_timeZ_jv)();
l3 = j0;
i0 = (*Z_envZ_tapos_block_prefixZ_iv)();
j1 = l3;
j2 = 1000000ull;
j1 = DIV_U(j1, j2);
i1 = (u32)(j1);
i0 += i1;
i1 = 179424691u;
i0 *= i1;
j0 = (u64)(i0);
(*Z_envZ_printuiZ_vj)(j0);

#authored by qpIlIpp (c) LetItPlay, 2019

samplesforarticle's People

Contributors

opcheese avatar

Watchers

James Cloos avatar

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.