Skip to content

Commit

Permalink
Merge pull request #1891 from skalenetwork/bug/IS-864-bls-sync-config
Browse files Browse the repository at this point in the history
Bug/is 864 bls sync config
  • Loading branch information
DmytroNazarenko authored May 16, 2024
2 parents e1f053a + 63eaca4 commit 35a2a78
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
repository: skalenetwork/skale-ci-integration_tests
ref: v3.18.0
ref: master
submodules: recursive
- name: Set up Node
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion libconsensus
5 changes: 4 additions & 1 deletion libethcore/ChainOperationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct NodeInfo {
bool syncNode;
bool archiveMode;
bool syncFromCatchup;
bool testSignatures;

NodeInfo( std::string _name = "TestNode", u256 _id = 1, std::string _ip = "127.0.0.11",
uint16_t _port = 11111, std::string _ip6 = "::1", uint16_t _port6 = 11111,
Expand All @@ -107,7 +108,8 @@ struct NodeInfo {
"11559732032986387107991004021392285783925812861821192530917403151452391805634",
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
"4082367875863433681332203403145435568316851327593401208105741076214120093531" },
bool _syncNode = false, bool _archiveMode = false, bool _syncFromCatchup = false ) {
bool _syncNode = false, bool _archiveMode = false, bool _syncFromCatchup = false,
bool _testSignatures = true ) {
name = _name;
id = _id;
ip = _ip;
Expand All @@ -122,6 +124,7 @@ struct NodeInfo {
syncNode = _syncNode;
archiveMode = _archiveMode;
syncFromCatchup = _syncFromCatchup;
testSignatures = _testSignatures;
}
};

Expand Down
34 changes: 17 additions & 17 deletions libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,40 +217,40 @@ void ChainParams::processSkaleConfigItems( ChainParams& cp, json_spirit::mObject
if ( cp.rotateAfterBlock_ < 0 )
cp.rotateAfterBlock_ = 0;

string ecdsaKeyName;
bool testSignatures = false;
try {
ecdsaKeyName = infoObj.at( "ecdsaKeyName" ).get_str();
testSignatures = infoObj.at( "testSignatures" ).get_bool();
} catch ( ... ) {
}

string ecdsaKeyName;
array< string, 4 > BLSPublicKeys;
array< string, 4 > commonBLSPublicKeys;
if ( !testSignatures ) {
ecdsaKeyName = infoObj.at( "ecdsaKeyName" ).get_str();

try {
js::mObject ima = infoObj.at( "wallets" ).get_obj().at( "ima" ).get_obj();

keyShareName = ima.at( "keyShareName" ).get_str();

t = ima.at( "t" ).get_int();

BLSPublicKeys[0] = ima["BLSPublicKey0"].get_str();
BLSPublicKeys[1] = ima["BLSPublicKey1"].get_str();
BLSPublicKeys[2] = ima["BLSPublicKey2"].get_str();
BLSPublicKeys[3] = ima["BLSPublicKey3"].get_str();

commonBLSPublicKeys[0] = ima["commonBLSPublicKey0"].get_str();
commonBLSPublicKeys[1] = ima["commonBLSPublicKey1"].get_str();
commonBLSPublicKeys[2] = ima["commonBLSPublicKey2"].get_str();
commonBLSPublicKeys[3] = ima["commonBLSPublicKey3"].get_str();
} catch ( ... ) {
// all or nothing
if ( !keyShareName.empty() )
throw;

if ( !syncNode ) {
keyShareName = ima.at( "keyShareName" ).get_str();

t = ima.at( "t" ).get_int();

BLSPublicKeys[0] = ima["BLSPublicKey0"].get_str();
BLSPublicKeys[1] = ima["BLSPublicKey1"].get_str();
BLSPublicKeys[2] = ima["BLSPublicKey2"].get_str();
BLSPublicKeys[3] = ima["BLSPublicKey3"].get_str();
}
}

cp.nodeInfo = { nodeName, nodeID, ip, static_cast< uint16_t >( port ), ip6,
static_cast< uint16_t >( port6 ), sgxServerUrl, ecdsaKeyName, keyShareName, BLSPublicKeys,
commonBLSPublicKeys, syncNode, archiveMode, syncFromCatchup };
commonBLSPublicKeys, syncNode, archiveMode, syncFromCatchup, testSignatures };

auto sChainObj = skaleObj.at( "sChain" ).get_obj();
SChain s{};
Expand Down
4 changes: 4 additions & 0 deletions libethereum/SchainPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ SchainPatchEnum getEnumForPatchName( const std::string& _patchName ) {
return SchainPatchEnum::SkipInvalidTransactionsPatch;
else if ( _patchName == "EIP1559TransactionsPatch" )
return SchainPatchEnum::EIP1559TransactionsPatch;
else if ( _patchName == "VerifyBlsSyncPatch" )
return SchainPatchEnum::VerifyBlsSyncPatch;
else if ( _patchName == "FlexibleDeploymentPatch" )
return SchainPatchEnum::FlexibleDeploymentPatch;
else
Expand Down Expand Up @@ -62,6 +64,8 @@ std::string getPatchNameForEnum( SchainPatchEnum _enumValue ) {
return "SelfdestructStorageLimitPatch";
case SchainPatchEnum::EIP1559TransactionsPatch:
return "EIP1559TransactionsPatch";
case SchainPatchEnum::VerifyBlsSyncPatch:
return "VerifyBlsSyncPatch";
case SchainPatchEnum::FlexibleDeploymentPatch:
return "FlexibleDeploymentPatch";
default:
Expand Down
5 changes: 5 additions & 0 deletions libethereum/SchainPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ DEFINE_SIMPLE_PATCH( SelfdestructStorageLimitPatch );
*/
DEFINE_SIMPLE_PATCH( EIP1559TransactionsPatch );

/*
* Enable bls signatures verification for sync node
*/
DEFINE_AMNESIC_PATCH( VerifyBlsSyncPatch );

/*
* Purpose: passing both transaction origin and sender to the ConfigController contract
* Version introduced: 3.19.0
Expand Down
1 change: 1 addition & 0 deletions libethereum/SchainPatchEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum class SchainPatchEnum {
SkipInvalidTransactionsPatch,
SelfdestructStorageLimitPatch,
EIP1559TransactionsPatch,
VerifyBlsSyncPatch,
FlexibleDeploymentPatch,
PatchesCount
};
Expand Down
38 changes: 20 additions & 18 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ std::unique_ptr< ConsensusInterface > DefaultConsensusFactory::create(

patchTimeStamps["verifyDaSigsPatchTimestamp"] =
m_client.chainParams().getPatchTimestamp( SchainPatchEnum::VerifyDaSigsPatch );
patchTimeStamps["verifyBlsSyncPatchTimestamp"] =
m_client.chainParams().getPatchTimestamp( SchainPatchEnum::VerifyBlsSyncPatch );

auto consensus_engine_ptr = make_unique< ConsensusEngine >( _extFace, m_client.number(), ts, 0,
patchTimeStamps, m_client.chainParams().sChain.consensusStorageLimit );
Expand All @@ -89,10 +91,8 @@ std::unique_ptr< ConsensusInterface > DefaultConsensusFactory::create(
this->fillSgxInfo( *consensus_engine_ptr );
}


this->fillPublicKeyInfo( *consensus_engine_ptr );


this->fillRotationHistory( *consensus_engine_ptr );

return consensus_engine_ptr;
Expand Down Expand Up @@ -143,29 +143,31 @@ void DefaultConsensusFactory::fillSgxInfo( ConsensusEngine& consensus ) const tr
}

void DefaultConsensusFactory::fillPublicKeyInfo( ConsensusEngine& consensus ) const try {
if ( m_client.chainParams().nodeInfo.testSignatures )
// no keys in tests
return;

const std::string sgxServerUrl = m_client.chainParams().nodeInfo.sgxServerUrl;

std::shared_ptr< std::vector< std::string > > ecdsaPublicKeys =
std::make_shared< std::vector< std::string > >();
for ( const auto& node : m_client.chainParams().sChain.nodes ) {
if ( node.publicKey.size() == 0 )
return; // just don't do anything
ecdsaPublicKeys->push_back( node.publicKey.substr( 2 ) );
}

std::vector< std::shared_ptr< std::vector< std::string > > > blsPublicKeys;
for ( const auto& node : m_client.chainParams().sChain.nodes ) {
std::vector< std::string > public_key_share( 4 );
if ( node.id != this->m_client.chainParams().nodeInfo.id ) {
public_key_share[0] = node.blsPublicKey[0];
public_key_share[1] = node.blsPublicKey[1];
public_key_share[2] = node.blsPublicKey[2];
public_key_share[3] = node.blsPublicKey[3];
public_key_share[0] = node.blsPublicKey.at( 0 );
public_key_share[1] = node.blsPublicKey.at( 1 );
public_key_share[2] = node.blsPublicKey.at( 2 );
public_key_share[3] = node.blsPublicKey.at( 3 );
} else {
public_key_share[0] = m_client.chainParams().nodeInfo.BLSPublicKeys[0];
public_key_share[1] = m_client.chainParams().nodeInfo.BLSPublicKeys[1];
public_key_share[2] = m_client.chainParams().nodeInfo.BLSPublicKeys[2];
public_key_share[3] = m_client.chainParams().nodeInfo.BLSPublicKeys[3];
public_key_share[0] = m_client.chainParams().nodeInfo.BLSPublicKeys.at( 0 );
public_key_share[1] = m_client.chainParams().nodeInfo.BLSPublicKeys.at( 1 );
public_key_share[2] = m_client.chainParams().nodeInfo.BLSPublicKeys.at( 2 );
public_key_share[3] = m_client.chainParams().nodeInfo.BLSPublicKeys.at( 3 );
}

blsPublicKeys.push_back(
Expand All @@ -179,11 +181,10 @@ void DefaultConsensusFactory::fillPublicKeyInfo( ConsensusEngine& consensus ) co
size_t n = m_client.chainParams().sChain.nodes.size();
size_t t = ( 2 * n + 1 ) / 3;

if ( ecdsaPublicKeys->size() && ecdsaPublicKeys->at( 0 ).size() && blsPublicKeys.size() &&
blsPublicKeys[0]->at( 0 ).size() )
consensus.setPublicKeyInfo( ecdsaPublicKeys, blsPublicKeysPtr, t, n );
consensus.setPublicKeyInfo(
ecdsaPublicKeys, blsPublicKeysPtr, t, n, m_client.chainParams().nodeInfo.syncNode );
} catch ( ... ) {
std::throw_with_nested( std::runtime_error( "Error filling SGX info (nodeGroups)" ) );
std::throw_with_nested( std::runtime_error( "Error filling public keys info (nodeGroups)" ) );
}


Expand All @@ -193,8 +194,9 @@ void DefaultConsensusFactory::fillRotationHistory( ConsensusEngine& consensus )
std::map< uint64_t, std::vector< uint64_t > > historicNodeGroups;
auto u256toUint64 = []( const dev::u256& u ) { return std::stoull( u.str() ); };
for ( const auto& nodeGroup : m_client.chainParams().sChain.nodeGroups ) {
std::vector< string > commonBLSPublicKey = { nodeGroup.blsPublicKey[0],
nodeGroup.blsPublicKey[1], nodeGroup.blsPublicKey[2], nodeGroup.blsPublicKey[3] };
std::vector< string > commonBLSPublicKey = { nodeGroup.blsPublicKey.at( 0 ),
nodeGroup.blsPublicKey.at( 1 ), nodeGroup.blsPublicKey.at( 2 ),
nodeGroup.blsPublicKey.at( 3 ) };
previousBLSKeys[nodeGroup.finishTs] = commonBLSPublicKey;
std::vector< uint64_t > nodes;
// add ecdsa keys info and historic groups info
Expand Down
4 changes: 2 additions & 2 deletions libethereum/ValidationSchemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void validateConfigJson( js::mObject const& _obj ) {
{ "snapshotIntervalSec", { { js::int_type }, JsonFieldPresence::Optional } },
{ "rotateAfterBlock", { { js::int_type }, JsonFieldPresence::Optional } },
{ "wallets", { { js::obj_type }, JsonFieldPresence::Optional } },
{ "ecdsaKeyName", { { js::str_type }, JsonFieldPresence::Required } },
{ "ecdsaKeyName", { { js::str_type }, JsonFieldPresence::Optional } },
{ "verifyImaMessagesViaLogsSearch",
{ { js::bool_type }, JsonFieldPresence::Optional } },
{ "verifyImaMessagesViaContractCall",
Expand Down Expand Up @@ -222,6 +222,7 @@ void validateConfigJson( js::mObject const& _obj ) {
{ "syncNode", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "archiveMode", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "syncFromCatchup", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "testSignatures", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "wallets", { { js::obj_type }, JsonFieldPresence::Optional } } } );

std::string keyShareName = "";
Expand Down Expand Up @@ -268,7 +269,6 @@ void validateConfigJson( js::mObject const& _obj ) {
{ "maxSkaledLeveldbStorageBytes", { { js::int_type }, JsonFieldPresence::Optional } },
{ "freeContractDeployment", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "multiTransactionMode", { { js::bool_type }, JsonFieldPresence::Optional } },
{ "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } },
{ "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } } },
[]( const string& _key ) {
// function fow allowing fields
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/libethereum/ClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static std::string const c_genesisInfoSkaleTest = std::string() +
"basePort": )E"+std::to_string( rand_port ) + R"E(,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112"
"testSignatures": true
},
"sChain": {
"schainName": "TestChain",
Expand Down Expand Up @@ -887,7 +887,7 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() +
"basePort": )E"+std::to_string( rand_port ) + R"E(,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112"
"testSignatures": true
},
"sChain": {
"schainName": "TestChain",
Expand Down Expand Up @@ -1002,7 +1002,7 @@ static std::string const c_skaleConfigString = R"E(
"nodeID": 1112,
"bindIP": "127.0.0.1",
"basePort": )E"+std::to_string( rand_port ) + R"E(,
"ecdsaKeyName": "NEK:fa112"
"testSignatures": true
},
"sChain": {
"schainName": "TestChain",
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/libethereum/PrecompiledConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"basePort": 1234,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112",
"testSignatures": true,
"wallets": {
"ima": {
"n": 1
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/libethereum/PrecompiledTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ static std::string const genesisInfoSkaleConfigTest = std::string() +
"basePort": 1234,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112",
"testSignatures": true,
"wallets": {
"ima": {
"n": 1
Expand Down
1 change: 1 addition & 0 deletions test/unittests/libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct SkaleHostFixture : public TestOutputHelperFixture {
chainParams.extraData = h256::random().asBytes();
chainParams.sChain.nodeGroups = { { {}, uint64_t(-1), {"0", "0", "1", "0"} } };
chainParams.nodeInfo.port = chainParams.nodeInfo.port6 = rand_port;
chainParams.nodeInfo.testSignatures = true;
chainParams.sChain.nodes[0].port = chainParams.sChain.nodes[0].port6 = rand_port;

// not 0-timestamp genesis - to test patch
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static std::string const c_genesisConfigString =
"basePort": )"+std::to_string( rand_port ) + R"(,
"logLevel": "trace",
"logLevelProposal": "trace",
"ecdsaKeyName": "NEK:fa112"
"testSignatures": true
},
"sChain": {
"schainName": "TestChain",
Expand Down

0 comments on commit 35a2a78

Please sign in to comment.