mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
add randomx registers
This commit is contained in:
parent
d32cc0df05
commit
dcc4641157
2 changed files with 102 additions and 35 deletions
111
src/page.h
111
src/page.h
|
@ -235,6 +235,70 @@ using namespace std;
|
||||||
using epee::string_tools::pod_to_hex;
|
using epee::string_tools::pod_to_hex;
|
||||||
using epee::string_tools::hex_to_pod;
|
using epee::string_tools::hex_to_pod;
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
std::string as_hex(T i)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << "0x" << setfill ('0') << setw(sizeof(T)*2)
|
||||||
|
<< hex << i;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct randomx_status
|
||||||
|
{
|
||||||
|
randomx::Program prog;
|
||||||
|
randomx::RegisterFile reg_file;
|
||||||
|
|
||||||
|
randomx::AssemblyGeneratorX86
|
||||||
|
get_asm()
|
||||||
|
{
|
||||||
|
randomx::AssemblyGeneratorX86 asmX86;
|
||||||
|
asmX86.generateProgram(prog);
|
||||||
|
return asmX86;
|
||||||
|
}
|
||||||
|
|
||||||
|
mstch::map
|
||||||
|
get_mstch()
|
||||||
|
{
|
||||||
|
auto asmx86 = get_asm();
|
||||||
|
|
||||||
|
stringstream ss1, ss2;
|
||||||
|
|
||||||
|
ss1 << prog;
|
||||||
|
asmx86.printCode(ss2);
|
||||||
|
|
||||||
|
mstch::map rx_map {
|
||||||
|
{"rx_code" , ss1.str()},
|
||||||
|
{"rx_code_asm", ss2.str()}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < randomx::RegistersCount; ++i)
|
||||||
|
{
|
||||||
|
rx_map["r"+std::to_string(i)] = as_hex(reg_file.r[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < randomx::RegistersCount/2; ++i)
|
||||||
|
{
|
||||||
|
rx_map["f"+std::to_string(i)] = rx_float_as_str(reg_file.f[i]);
|
||||||
|
rx_map["e"+std::to_string(i)] = rx_float_as_str(reg_file.e[i]);
|
||||||
|
rx_map["a"+std::to_string(i)] = rx_float_as_str(reg_file.a[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rx_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
rx_float_as_str(randomx::fpu_reg_t fpu)
|
||||||
|
{
|
||||||
|
uint64_t* lo = reinterpret_cast<uint64_t*>(&fpu.lo);
|
||||||
|
uint64_t* hi = reinterpret_cast<uint64_t*>(&fpu.hi);
|
||||||
|
|
||||||
|
return "{" + as_hex(*lo) + ", " + as_hex(*hi)+ "}";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The tx_details struct
|
* @brief The tx_details struct
|
||||||
*
|
*
|
||||||
|
@ -1397,12 +1461,9 @@ show_randomx(uint64_t _blk_height)
|
||||||
|
|
||||||
for (auto& rxc: rx_code)
|
for (auto& rxc: rx_code)
|
||||||
{
|
{
|
||||||
rx_code_str.push_back(
|
mstch::map rx_map = rxc.get_mstch();
|
||||||
mstch::map {
|
rx_map["rx_code_idx"] = code_idx++;
|
||||||
{"rx_code_idx", code_idx++},
|
rx_code_str.push_back(rx_map);
|
||||||
{"rx_code", std::move(rxc.first)},
|
|
||||||
{"rx_code_asm", std::move(rxc.second)}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mstch::map context {
|
mstch::map context {
|
||||||
|
@ -7129,14 +7190,14 @@ get_tx(string const& tx_hash_str,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<std::pair<string, string>>
|
vector<randomx_status>
|
||||||
get_randomx_code(uint64_t blk_height,
|
get_randomx_code(uint64_t blk_height,
|
||||||
block const& blk,
|
block const& blk,
|
||||||
crypto::hash const& blk_hash)
|
crypto::hash const& blk_hash)
|
||||||
{
|
{
|
||||||
static std::mutex mtx;
|
static std::mutex mtx;
|
||||||
|
|
||||||
vector<std::pair<string, string>> rx_code;
|
vector<randomx_status> rx_code;
|
||||||
|
|
||||||
blobdata bd = get_block_hashing_blob(blk);
|
blobdata bd = get_block_hashing_blob(blk);
|
||||||
|
|
||||||
|
@ -7167,47 +7228,33 @@ get_randomx_code(uint64_t blk_height,
|
||||||
// randomx::Program* prg
|
// randomx::Program* prg
|
||||||
// = reinterpret_cast<randomx::Program*>(
|
// = reinterpret_cast<randomx::Program*>(
|
||||||
// reinterpret_cast<char*>(rx_vm) + 64);
|
// reinterpret_cast<char*>(rx_vm) + 64);
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
randomx::Program prg;
|
|
||||||
randomx::RegisterFile reg;
|
|
||||||
|
|
||||||
for (int chain = 0; chain < RANDOMX_PROGRAM_COUNT - 1; ++chain)
|
for (int chain = 0; chain < RANDOMX_PROGRAM_COUNT - 1; ++chain)
|
||||||
{
|
{
|
||||||
rx_vm->run(&tempHash);
|
rx_vm->run(&tempHash);
|
||||||
|
|
||||||
blake2b(tempHash, sizeof(tempHash),
|
blake2b(tempHash, sizeof(tempHash),
|
||||||
rx_vm->getRegisterFile(),
|
rx_vm->getRegisterFile(),
|
||||||
sizeof(randomx::RegisterFile), nullptr, 0);
|
sizeof(randomx::RegisterFile), nullptr, 0);
|
||||||
|
|
||||||
prg = rx_vm->getProgram();
|
rx_code.push_back({});
|
||||||
reg = *(rx_vm->getRegisterFile());
|
|
||||||
|
|
||||||
stringstream ss, ss2;
|
rx_code.back().prog = rx_vm->getProgram();
|
||||||
ss << prg;
|
rx_code.back().reg_file = *(rx_vm->getRegisterFile());
|
||||||
|
|
||||||
|
|
||||||
randomx::AssemblyGeneratorX86 asmX86;
|
|
||||||
asmX86.generateProgram(prg);
|
|
||||||
asmX86.printCode(ss2);
|
|
||||||
|
|
||||||
rx_code.emplace_back(ss.str(), ss2.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rx_vm->run(&tempHash);
|
rx_vm->run(&tempHash);
|
||||||
|
|
||||||
prg = rx_vm->getProgram();
|
rx_code.push_back({});
|
||||||
|
|
||||||
stringstream ss, ss2;
|
rx_code.back().prog = rx_vm->getProgram();
|
||||||
ss << prg;
|
rx_code.back().reg_file = *(rx_vm->getRegisterFile());
|
||||||
|
|
||||||
randomx::AssemblyGeneratorX86 asmX86;
|
|
||||||
asmX86.generateProgram(prg);
|
|
||||||
asmX86.printCode(ss2);
|
|
||||||
|
|
||||||
rx_code.emplace_back(ss.str(), ss2.str());
|
// crypto::hash res2;
|
||||||
|
// rx_vm->getFinalResult(res2.data, RANDOMX_HASH_SIZE);
|
||||||
// crypto::hash res2;
|
|
||||||
// rx_vm->getFinalResult(res2.data, RANDOMX_HASH_SIZE);
|
|
||||||
|
|
||||||
// cout << "pow2: " << pod_to_hex(res2) << endl;
|
// cout << "pow2: " << pod_to_hex(res2) << endl;
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,33 @@
|
||||||
<H4>Block hash (height): {{blk_hash}} ({{blk_height}})</H4>
|
<H4>Block hash (height): {{blk_hash}} ({{blk_height}})</H4>
|
||||||
<h4>
|
<h4>
|
||||||
Eight RandomX and correspoding assembly x86 programs used
|
Eight RandomX and correspoding assembly x86 programs used
|
||||||
to calcualte PoW hash of the block.<br/>The RandomX programs
|
to calcualte the PoW hash of the block.<br/>
|
||||||
are executed on RandomX virtual machine.
|
The RandomX programs are executed on RandomX virtual machine. <br/>
|
||||||
|
Initial values of the integer and floating point registers in the machine are also provided.
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
{{#rx_codes}}
|
{{#rx_codes}}
|
||||||
<h3> Program #{{rx_code_idx}}</h3>
|
<h3> Program #{{rx_code_idx}}</h3>
|
||||||
<table class="center" style="width: 50%; margin-top:10px">
|
<table class="center" style="width: 60%; margin-top:10px">
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
Integer registers R:<br/><br/>
|
||||||
|
r0: {{r0}}, r1: {{r1}}, r2: {{r2}}, r3: {{r3}}<br/>
|
||||||
|
r4: {{r4}}, r5: {{r5}}, r6: {{r6}}, r7: {{r7}}<br/><br/>
|
||||||
|
Floating point registers F {lo, hi}:<br/><br/>
|
||||||
|
f0: {{f0}}, f1: {{f1}}<br/>
|
||||||
|
f2: {{f2}}, f3: {{f3}}<br/><br/>
|
||||||
|
|
||||||
|
Floating point registers E {lo, hi}:<br/><br/>
|
||||||
|
e0: {{e0}}, e1: {{e1}}<br/>
|
||||||
|
e2: {{e2}}, e3: {{e3}}<br/><br/>
|
||||||
|
|
||||||
|
Floating point registers A {lo, hi}:<br/><br/>
|
||||||
|
a0: {{a0}}, a1: {{a1}}<br/>
|
||||||
|
a2: {{a2}}, a3: {{a3}}<br/><br/>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: left;">RandomX code</td>
|
<td style="text-align: left;">RandomX code</td>
|
||||||
<td style="text-align: left;">ASM x86</td>
|
<td style="text-align: left;">ASM x86</td>
|
||||||
|
|
Loading…
Reference in a new issue