-
Notifications
You must be signed in to change notification settings - Fork 42
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
Bug/1702 adopt precompiled oracle #1713
Changes from 8 commits
685fd91
a733b76
b7cd5a5
295b850
786882f
e9b63e9
4f22ffb
a348f52
3815c22
ee9c48a
aa4c0d8
95215c7
4d55443
7f136c5
ea28913
3652a82
41ddce9
399e9b1
cfbd435
80618dd
582b526
ea694fc
ca16ebf
4995613
edd62d4
aaab497
3b122e5
4b51081
e411718
a504090
1a67380
7700738
c8921f6
23a5437
d301345
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -756,6 +756,26 @@ | |
return uValue; | ||
} | ||
|
||
static bool isCallToHistoricData( const std::string& callData ) { | ||
return skutils::tools::wildcmp( "skaleConfig.sChain.nodes.*", callData.c_str() ); | ||
} | ||
|
||
static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std::string& callData ) { | ||
size_t numberLength = callData.find( ']' ) - callData.find( '[' ) - 1; | ||
unsigned id = std::stoul( callData.substr( callData.find( '[' ) + 1, numberLength ) ); | ||
std::string fieldName; | ||
if ( callData.find( "id" ) != std::string::npos ) { | ||
fieldName = "id"; | ||
} else if ( callData.find( "schainIndex" ) != std::string::npos ) { | ||
fieldName = "schainIndex"; | ||
} else if ( callData.find( "owner" ) != std::string::npos ) { | ||
fieldName = "owner"; | ||
} else { | ||
fieldName = "unknown field"; | ||
} | ||
return { fieldName, id }; | ||
} | ||
|
||
ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { | ||
try { | ||
size_t lengthName; | ||
|
@@ -767,18 +787,37 @@ | |
|
||
if ( !g_configAccesssor ) | ||
throw std::runtime_error( "Config accessor was not initialized" ); | ||
nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); | ||
nlohmann::json joValue = | ||
skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); | ||
std::string strValue = skutils::tools::trim_copy( | ||
joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); | ||
|
||
std::string strValue; | ||
// call to skaleConfig.sChain.nodes means call to the historic data | ||
// need to proccess it in a different way | ||
if ( isCallToHistoricData( rawName ) ) { | ||
if ( !g_skaleHost ) | ||
throw std::runtime_error( "SkaleHost accessor was not initialized" ); | ||
|
||
std::string field; | ||
unsigned id; | ||
std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); | ||
if ( field == "id" ) { | ||
strValue = g_skaleHost->getHistoricNodeId( id ); | ||
} else if ( field == "schainIndex" ) { | ||
strValue = g_skaleHost->getHistoricNodeIndex( id ); | ||
} else { | ||
throw std::runtime_error( "Incorrect config field" ); | ||
} | ||
} else { | ||
nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); | ||
nlohmann::json joValue = | ||
skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); | ||
strValue = skutils::tools::trim_copy( | ||
joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); | ||
} | ||
Comment on lines
+826
to
+832
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change so that the else {} part is only used when the patch is enabled, since stat_extract_at_path is unsecure and complex. If it is needed, it needs to be rewritten in a clean and secure |
||
|
||
// dev::u256 uValue( strValue.c_str() ); | ||
dev::u256 uValue = stat_parse_u256_hex_or_dec( strValue ); | ||
// std::cout << "------------ Loaded config var \"" | ||
// << rawName << "\" value is " << uValue | ||
// << "\n"; | ||
|
||
bytes response = toBigEndian( uValue ); | ||
return { true, response }; | ||
} catch ( std::exception& ex ) { | ||
|
@@ -807,11 +846,30 @@ | |
|
||
if ( !g_configAccesssor ) | ||
throw std::runtime_error( "Config accessor was not initialized" ); | ||
nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); | ||
nlohmann::json joValue = | ||
skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); | ||
std::string strValue = skutils::tools::trim_copy( | ||
joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); | ||
|
||
std::string strValue; | ||
// call to skaleConfig.sChain.nodes means call to the historic data | ||
// need to proccess it in a different way | ||
if ( isCallToHistoricData( rawName ) ) { | ||
if ( !g_skaleHost ) | ||
throw std::runtime_error( "SkaleHost accessor was not initialized" ); | ||
|
||
std::string field; | ||
unsigned id; | ||
std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); | ||
if ( field == "owner" ) { | ||
strValue = g_skaleHost->getHistoricNodeOwner( id ); | ||
} else { | ||
throw std::runtime_error( "Incorrect config field" ); | ||
} | ||
} else { | ||
nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); | ||
nlohmann::json joValue = | ||
skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); | ||
strValue = skutils::tools::trim_copy( | ||
joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); | ||
} | ||
|
||
dev::u256 uValue( strValue.c_str() ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c_str() is not needed here since the constructor takes std::string |
||
|
||
bytes response = toBigEndian( uValue ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please improve so that exact matches are always used, so inccorect strings do not result in a match