From fed61bb638f5cbaae8c98ccb125fd77400cf4d70 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 24 Apr 2024 00:13:42 +0000 Subject: [PATCH 01/11] #1876 Add isAddressWhitelistedCallData overload --- libethcore/Common.cpp | 5 +++++ libethcore/Common.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index 1c9772b55..4eaafc31f 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -112,6 +112,11 @@ bytes isAddressWhitelistedCallData( Address const& _deployer ) { return fromHex( "13f44d10000000000000000000000000" + _deployer.hex() ); } +bytes isAddressWhitelistedCallData( Address const& _deployer, Address const& _origin ) { + return fromHex( "b31fd4e6000000000000000000000000" + _deployer.hex() + + "000000000000000000000000" + _origin.hex() ); +} + bytes getMultitransactionCallData() { return fromHex( "0xbad0396e" ); } diff --git a/libethcore/Common.h b/libethcore/Common.h index 980aa7a30..7b2a47cf4 100644 --- a/libethcore/Common.h +++ b/libethcore/Common.h @@ -61,6 +61,9 @@ extern const Address c_configControllerContractAddress; /// Formatting call data for deployment control contract bytes isAddressWhitelistedCallData( Address const& _deployer ); +/// Formatting call data for deployment control contract, considering tx origin +bytes isAddressWhitelistedCallData( Address const& _deployer, Address const& _origin ); + /// Formatting call data for multitransaction contract bytes getMultitransactionCallData(); From 7e944cd10bf9b536fa3af6aebd98e1fd43483ff9 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 24 Apr 2024 17:37:03 +0000 Subject: [PATCH 02/11] #1876 Add FlexibleDeploymentPatch --- libethereum/SchainPatch.cpp | 4 ++++ libethereum/SchainPatch.h | 6 ++++++ libethereum/SchainPatchEnum.h | 1 + 3 files changed, 11 insertions(+) diff --git a/libethereum/SchainPatch.cpp b/libethereum/SchainPatch.cpp index 1ae076376..7ca28f839 100644 --- a/libethereum/SchainPatch.cpp +++ b/libethereum/SchainPatch.cpp @@ -28,6 +28,8 @@ SchainPatchEnum getEnumForPatchName( const std::string& _patchName ) { return SchainPatchEnum::StorageDestructionPatch; else if ( _patchName == "SkipInvalidTransactionsPatch" ) return SchainPatchEnum::SkipInvalidTransactionsPatch; + else if ( _patchName == "FlexibleDeploymentPatch" ) + return SchainPatchEnum::FlexibleDeploymentPatch; else throw std::out_of_range( _patchName ); } @@ -56,6 +58,8 @@ std::string getPatchNameForEnum( SchainPatchEnum _enumValue ) { return "SkipInvalidTransactionsPatch"; case SchainPatchEnum::SelfdestructStorageLimitPatch: return "SelfdestructStorageLimitPatch"; + case SchainPatchEnum::FlexibleDeploymentPatch: + return "FlexibleDeploymentPatch"; default: throw std::out_of_range( "UnknownPatch #" + std::to_string( static_cast< size_t >( _enumValue ) ) ); diff --git a/libethereum/SchainPatch.h b/libethereum/SchainPatch.h index d8fabce97..63650d7ce 100644 --- a/libethereum/SchainPatch.h +++ b/libethereum/SchainPatch.h @@ -130,4 +130,10 @@ DEFINE_AMNESIC_PATCH( StorageDestructionPatch ); */ DEFINE_SIMPLE_PATCH( SelfdestructStorageLimitPatch ); +/* + * Purpose: passing both tx origin and tx sender into ConfigController + * Version introduced: 3.19.0 + */ +DEFINE_SIMPLE_PATCH( FlexibleDeploymentPatch ); + #endif // SCHAINPATCH_H diff --git a/libethereum/SchainPatchEnum.h b/libethereum/SchainPatchEnum.h index b1f439211..5e713b1e6 100644 --- a/libethereum/SchainPatchEnum.h +++ b/libethereum/SchainPatchEnum.h @@ -16,6 +16,7 @@ enum class SchainPatchEnum { StorageDestructionPatch, SkipInvalidTransactionsPatch, SelfdestructStorageLimitPatch, + FlexibleDeploymentPatch, PatchesCount }; From c928244bd88c19e91cf65a62ab460d32aae995ef Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 25 Apr 2024 19:42:10 +0000 Subject: [PATCH 03/11] #1876 Pass 2 parameters if patch is enabled --- libethereum/Executive.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 70a945efc..6dbe96472 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -468,7 +469,13 @@ bool Executive::go( OnOpFunc const& _onOp ) { // Create VM instance. Force Interpreter if tracing requested. auto vm = VMFactory::create(); if ( m_isCreation ) { - bytes in = isAddressWhitelistedCallData( m_ext->caller ); + bytes in; + if ( FlexibleDeploymentPatch::isEnabledWhen( + m_envInfo.committedBlockTimestamp() ) ) { + in = isAddressWhitelistedCallData( m_ext->caller, m_ext->origin ); + } else { + in = isAddressWhitelistedCallData( m_ext->caller ); + } unique_ptr< CallParameters > deploymentCallParams( new CallParameters( SystemAddress, c_configControllerContractAddress, c_configControllerContractAddress, 0, 0, m_gas, From 779ecb089600296bd70f9d4ad34789a8ef4ffc9d Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Fri, 10 May 2024 15:12:22 +0000 Subject: [PATCH 04/11] #1876 Add unit test for new deployment control --- libethereum/SchainPatch.h | 2 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 114 ++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/libethereum/SchainPatch.h b/libethereum/SchainPatch.h index 63650d7ce..10f806568 100644 --- a/libethereum/SchainPatch.h +++ b/libethereum/SchainPatch.h @@ -131,7 +131,7 @@ DEFINE_AMNESIC_PATCH( StorageDestructionPatch ); DEFINE_SIMPLE_PATCH( SelfdestructStorageLimitPatch ); /* - * Purpose: passing both tx origin and tx sender into ConfigController + * Purpose: passing both transaction origin and sender to the ConfigController contract * Version introduced: 3.19.0 */ DEFINE_SIMPLE_PATCH( FlexibleDeploymentPatch ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 6e5d772f6..68d733f59 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -2896,6 +2896,120 @@ BOOST_AUTO_TEST_CASE( deploy_controller_generation2 ) { BOOST_REQUIRE( code.asString().substr( 2 ) == compiled.substr( 58 ) ); } +BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { + + // pragma solidity ^0.8.9; + + // contract ConfigController { + // bool public freeContractDeployment = false; + + // function isAddressWhitelisted(address addr) external view returns (bool) { + // return freeContractDeployment; + // } + + // function isAddressWhitelisted(address sender, address origin) + // external view returns (bool) { + // return freeContractDeployment; + // } + + // function setFreeContractDeployment() external { + // freeContractDeployment = true; + // } + // } + + string configControllerV2 = + "0x608060405234801561001057600080fd5b506004361061004c576000" + "3560e01c806313f44d1014610051578063a2306c4f14610081578063b3" + "1fd4e61461009f578063f7e2a91b146100cf575b600080fd5b61006b60" + "04803603810190610066919061019a565b6100d9565b60405161007891" + "906101e2565b60405180910390f35b6100896100f1565b604051610096" + "91906101e2565b60405180910390f35b6100b960048036038101906100" + "b491906101fd565b610102565b6040516100c691906101e2565b604051" + "80910390f35b6100d761011b565b005b60008060009054906101000a90" + "0460ff169050919050565b60008054906101000a900460ff1681565b60" + "008060009054906101000a900460ff16905092915050565b6001600080" + "6101000a81548160ff021916908315150217905550565b600080fd5b60" + "0073ffffffffffffffffffffffffffffffffffffffff82169050919050" + "565b60006101678261013c565b9050919050565b6101778161015c565b" + "811461018257600080fd5b50565b6000813590506101948161016e565b" + "92915050565b6000602082840312156101b0576101af610137565b5b60" + "006101be84828501610185565b91505092915050565b60008115159050" + "919050565b6101dc816101c7565b82525050565b600060208201905061" + "01f760008301846101d3565b92915050565b6000806040838503121561" + "021457610213610137565b5b600061022285828601610185565b925050" + "602061023385828601610185565b915050925092905056fea264697066" + "73582212200d0a9423308153222b80b5b50861993fb06e77a92aba37af" + "6c7fc23105a7138264736f6c634300080b0033"; + + std::string _config = c_genesisGeneration2ConfigString; + Json::Value ret; + Json::Reader().parse( _config, ret ); + ret["accounts"]["0xD2002000000000000000000000000000000000d2"]["code"] = configControllerV2; + Json::FastWriter fastWriter; + std::string config = fastWriter.write( ret ); + + JsonRpcFixture fixture(config, false, false, true ); + Address senderAddress = fixture.coinbase.address(); + fixture.client->setAuthor( senderAddress ); + + // contract test { + // function f(uint a) returns(uint d) { return a * 7; } + // } + + string compiled = + "6080604052341561000f57600080fd5b60b98061001d6000396000f300" + "608060405260043610603f576000357c01000000000000000000000000" + "00000000000000000000000000000000900463ffffffff168063b3de64" + "8b146044575b600080fd5b3415604e57600080fd5b606a600480360381" + "019080803590602001909291905050506080565b604051808281526020" + "0191505060405180910390f35b60006007820290509190505600a16562" + "7a7a72305820f294e834212334e2978c6dd090355312a3f0f9476b8eb9" + "8fb480406fc2728a960029"; + + + Json::Value deployContractWithoutRoleTx; + deployContractWithoutRoleTx["from"] = senderAddress.hex(); + deployContractWithoutRoleTx["code"] = compiled; + deployContractWithoutRoleTx["gas"] = "1000000"; + deployContractWithoutRoleTx["gasPrice"] = fixture.rpcClient->eth_gasPrice(); + + string txHash = fixture.rpcClient->eth_sendTransaction( deployContractWithoutRoleTx ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE_EQUAL( receipt["status"], string( "0x0" ) ); + + Json::Value code = + fixture.rpcClient->eth_getCode( receipt["contractAddress"].asString(), "latest" ); + BOOST_REQUIRE( code.asString() == "0x" ); + + // Allow deploy by calling setFreeContractDeployment() + Json::Value grantDeployerRoleTx; + grantDeployerRoleTx["data"] = "0xf7e2a91b"; + grantDeployerRoleTx["from"] = senderAddress.hex(); + grantDeployerRoleTx["to"] = "0xD2002000000000000000000000000000000000D2"; + grantDeployerRoleTx["gasPrice"] = fixture.rpcClient->eth_gasPrice(); + grantDeployerRoleTx["gas"] = toJS( "1000000" ); + txHash = fixture.rpcClient->eth_sendTransaction( grantDeployerRoleTx ); + BOOST_REQUIRE( !txHash.empty() ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + Json::Value deployContractTx; + deployContractTx["from"] = senderAddress.hex(); + deployContractTx["code"] = compiled; + deployContractTx["gas"] = "1000000"; + deployContractTx["gasPrice"] = fixture.rpcClient->eth_gasPrice(); + + txHash = fixture.rpcClient->eth_sendTransaction( deployContractTx ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE_EQUAL( receipt["status"], string( "0x1" ) ); + BOOST_REQUIRE( !receipt["contractAddress"].isNull() ); + code = fixture.rpcClient->eth_getCode( receipt["contractAddress"].asString(), "latest" ); + BOOST_REQUIRE( code.asString().substr( 2 ) == compiled.substr( 58 ) ); +} + BOOST_AUTO_TEST_CASE( filestorage_generation2 ) { JsonRpcFixture fixture(c_genesisGeneration2ConfigString, false, false, true); From fa24eab4f1cb4ea9c1bd360816304adf03d4f3d4 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 13 May 2024 17:26:08 +0000 Subject: [PATCH 05/11] #1876 Change call signature --- libethcore/Common.cpp | 6 +++--- libethcore/Common.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index 4eaafc31f..bafe6df78 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -112,9 +112,9 @@ bytes isAddressWhitelistedCallData( Address const& _deployer ) { return fromHex( "13f44d10000000000000000000000000" + _deployer.hex() ); } -bytes isAddressWhitelistedCallData( Address const& _deployer, Address const& _origin ) { - return fromHex( "b31fd4e6000000000000000000000000" + _deployer.hex() + - "000000000000000000000000" + _origin.hex() ); +bytes isDeploymentAllowedCallData( Address const& _origin, Address const& _deployer ) { + return fromHex( "d0f557f4000000000000000000000000" + _origin.hex() + + "000000000000000000000000" + _deployer.hex() ); } bytes getMultitransactionCallData() { diff --git a/libethcore/Common.h b/libethcore/Common.h index 7b2a47cf4..2fd143b93 100644 --- a/libethcore/Common.h +++ b/libethcore/Common.h @@ -62,7 +62,7 @@ extern const Address c_configControllerContractAddress; bytes isAddressWhitelistedCallData( Address const& _deployer ); /// Formatting call data for deployment control contract, considering tx origin -bytes isAddressWhitelistedCallData( Address const& _deployer, Address const& _origin ); +bytes isDeploymentAllowedCallData( Address const& _origin, Address const& _deployer ); /// Formatting call data for multitransaction contract bytes getMultitransactionCallData(); From 0c1e7ba6d81d13cd6ad8e58a56b1760d5108886f Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 13 May 2024 17:45:30 +0000 Subject: [PATCH 06/11] #1876 Change call signature --- libethcore/Common.cpp | 12 ++++++++++++ libethereum/Executive.cpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index bafe6df78..431d67763 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -109,10 +109,22 @@ std::string formatBalance( bigint const& _b ) { } bytes isAddressWhitelistedCallData( Address const& _deployer ) { + // Forming calldata for isAddressWhitelisted call on ConfigController smart contract: + // 13f44d1 - selector of isAddressWhitelisted function + // 000000000000000000000000 - 12-byte offset for sender address + // _deployer - 20-byte sender address + return fromHex( "13f44d10000000000000000000000000" + _deployer.hex() ); } bytes isDeploymentAllowedCallData( Address const& _origin, Address const& _deployer ) { + // Forming calldata for isDeploymentAllowed call on ConfigController smart contract: + // d0f557f4 - selector of isDeploymentAllowed function + // 000000000000000000000000 - 12-byte offset for origin address + // _origin - 20-byte origin address + // 000000000000000000000000 - 12-byte offset for sender address + // _deployer - 20-byte sender address + return fromHex( "d0f557f4000000000000000000000000" + _origin.hex() + "000000000000000000000000" + _deployer.hex() ); } diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 6dbe96472..f1b46c440 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -472,7 +472,7 @@ bool Executive::go( OnOpFunc const& _onOp ) { bytes in; if ( FlexibleDeploymentPatch::isEnabledWhen( m_envInfo.committedBlockTimestamp() ) ) { - in = isAddressWhitelistedCallData( m_ext->caller, m_ext->origin ); + in = isDeploymentAllowedCallData( m_ext->origin, m_ext->caller ); } else { in = isAddressWhitelistedCallData( m_ext->caller ); } From bf916a5e44152c6fd8d30c8a47842b21f9be4dcd Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 13 May 2024 18:52:34 +0000 Subject: [PATCH 07/11] #1876 Update unit test --- libethcore/Common.cpp | 4 ++-- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 28 ++++------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index 431d67763..678846e46 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -109,7 +109,7 @@ std::string formatBalance( bigint const& _b ) { } bytes isAddressWhitelistedCallData( Address const& _deployer ) { - // Forming calldata for isAddressWhitelisted call on ConfigController smart contract: + // Generating calldata for isAddressWhitelisted call to ConfigController smart contract: // 13f44d1 - selector of isAddressWhitelisted function // 000000000000000000000000 - 12-byte offset for sender address // _deployer - 20-byte sender address @@ -118,7 +118,7 @@ bytes isAddressWhitelistedCallData( Address const& _deployer ) { } bytes isDeploymentAllowedCallData( Address const& _origin, Address const& _deployer ) { - // Forming calldata for isDeploymentAllowed call on ConfigController smart contract: + // Generating calldata for isDeploymentAllowed call to ConfigController smart contract: // d0f557f4 - selector of isDeploymentAllowed function // 000000000000000000000000 - 12-byte offset for origin address // _origin - 20-byte origin address diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 68d733f59..e19de7a3d 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -2904,10 +2904,10 @@ BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { // bool public freeContractDeployment = false; // function isAddressWhitelisted(address addr) external view returns (bool) { - // return freeContractDeployment; + // return false; // } - // function isAddressWhitelisted(address sender, address origin) + // function isDeploymentAllowed(address origin, address sender) // external view returns (bool) { // return freeContractDeployment; // } @@ -2918,33 +2918,13 @@ BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { // } string configControllerV2 = - "0x608060405234801561001057600080fd5b506004361061004c576000" - "3560e01c806313f44d1014610051578063a2306c4f14610081578063b3" - "1fd4e61461009f578063f7e2a91b146100cf575b600080fd5b61006b60" - "04803603810190610066919061019a565b6100d9565b60405161007891" - "906101e2565b60405180910390f35b6100896100f1565b604051610096" - "91906101e2565b60405180910390f35b6100b960048036038101906100" - "b491906101fd565b610102565b6040516100c691906101e2565b604051" - "80910390f35b6100d761011b565b005b60008060009054906101000a90" - "0460ff169050919050565b60008054906101000a900460ff1681565b60" - "008060009054906101000a900460ff16905092915050565b6001600080" - "6101000a81548160ff021916908315150217905550565b600080fd5b60" - "0073ffffffffffffffffffffffffffffffffffffffff82169050919050" - "565b60006101678261013c565b9050919050565b6101778161015c565b" - "811461018257600080fd5b50565b6000813590506101948161016e565b" - "92915050565b6000602082840312156101b0576101af610137565b5b60" - "006101be84828501610185565b91505092915050565b60008115159050" - "919050565b6101dc816101c7565b82525050565b600060208201905061" - "01f760008301846101d3565b92915050565b6000806040838503121561" - "021457610213610137565b5b600061022285828601610185565b925050" - "602061023385828601610185565b915050925092905056fea264697066" - "73582212200d0a9423308153222b80b5b50861993fb06e77a92aba37af" - "6c7fc23105a7138264736f6c634300080b0033"; + "0x608060405234801561001057600080fd5b506004361061004c5760003560e01c806313f44d1014610051578063a2306c4f14610081578063d0f557f41461009f578063f7e2a91b146100cf575b600080fd5b61006b60048036038101906100669190610189565b6100d9565b60405161007891906101d1565b60405180910390f35b6100896100e0565b60405161009691906101d1565b60405180910390f35b6100b960048036038101906100b491906101ec565b6100f1565b6040516100c691906101d1565b60405180910390f35b6100d761010a565b005b6000919050565b60008054906101000a900460ff1681565b60008060009054906101000a900460ff16905092915050565b60016000806101000a81548160ff021916908315150217905550565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101568261012b565b9050919050565b6101668161014b565b811461017157600080fd5b50565b6000813590506101838161015d565b92915050565b60006020828403121561019f5761019e610126565b5b60006101ad84828501610174565b91505092915050565b60008115159050919050565b6101cb816101b6565b82525050565b60006020820190506101e660008301846101c2565b92915050565b6000806040838503121561020357610202610126565b5b600061021185828601610174565b925050602061022285828601610174565b915050925092905056fea2646970667358221220b5f971b16f7bbba22272b2207e02f10abf1682c17fe636c7bf6406c5cae5716064736f6c63430008090033"; std::string _config = c_genesisGeneration2ConfigString; Json::Value ret; Json::Reader().parse( _config, ret ); ret["accounts"]["0xD2002000000000000000000000000000000000d2"]["code"] = configControllerV2; + ret["skaleConfig"]["sChain"]["flexibleDeploymentPatchTimestamp"] = 1; Json::FastWriter fastWriter; std::string config = fastWriter.write( ret ); From 994c436b9742ffcbc260899d861bff88afe23661 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 13 May 2024 18:54:19 +0000 Subject: [PATCH 08/11] #1876 Update unit test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index e19de7a3d..22ab39c8f 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -2918,7 +2918,27 @@ BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { // } string configControllerV2 = - "0x608060405234801561001057600080fd5b506004361061004c5760003560e01c806313f44d1014610051578063a2306c4f14610081578063d0f557f41461009f578063f7e2a91b146100cf575b600080fd5b61006b60048036038101906100669190610189565b6100d9565b60405161007891906101d1565b60405180910390f35b6100896100e0565b60405161009691906101d1565b60405180910390f35b6100b960048036038101906100b491906101ec565b6100f1565b6040516100c691906101d1565b60405180910390f35b6100d761010a565b005b6000919050565b60008054906101000a900460ff1681565b60008060009054906101000a900460ff16905092915050565b60016000806101000a81548160ff021916908315150217905550565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101568261012b565b9050919050565b6101668161014b565b811461017157600080fd5b50565b6000813590506101838161015d565b92915050565b60006020828403121561019f5761019e610126565b5b60006101ad84828501610174565b91505092915050565b60008115159050919050565b6101cb816101b6565b82525050565b60006020820190506101e660008301846101c2565b92915050565b6000806040838503121561020357610202610126565b5b600061021185828601610174565b925050602061022285828601610174565b915050925092905056fea2646970667358221220b5f971b16f7bbba22272b2207e02f10abf1682c17fe636c7bf6406c5cae5716064736f6c63430008090033"; + "0x608060405234801561001057600080fd5b506004361061004c576000" + "3560e01c806313f44d1014610051578063a2306c4f14610081578063d0" + "f557f41461009f578063f7e2a91b146100cf575b600080fd5b61006b60" + "048036038101906100669190610189565b6100d9565b60405161007891" + "906101d1565b60405180910390f35b6100896100e0565b604051610096" + "91906101d1565b60405180910390f35b6100b960048036038101906100" + "b491906101ec565b6100f1565b6040516100c691906101d1565b604051" + "80910390f35b6100d761010a565b005b6000919050565b600080549061" + "01000a900460ff1681565b60008060009054906101000a900460ff1690" + "5092915050565b60016000806101000a81548160ff0219169083151502" + "17905550565b600080fd5b600073ffffffffffffffffffffffffffffff" + "ffffffffff82169050919050565b60006101568261012b565b90509190" + "50565b6101668161014b565b811461017157600080fd5b50565b600081" + "3590506101838161015d565b92915050565b6000602082840312156101" + "9f5761019e610126565b5b60006101ad84828501610174565b91505092" + "915050565b60008115159050919050565b6101cb816101b6565b825250" + "50565b60006020820190506101e660008301846101c2565b9291505056" + "5b6000806040838503121561020357610202610126565b5b6000610211" + "85828601610174565b925050602061022285828601610174565b915050" + "925092905056fea2646970667358221220b5f971b16f7bbba22272b220" + "7e02f10abf1682c17fe636c7bf6406c5cae5716064736f6c63430008090033"; std::string _config = c_genesisGeneration2ConfigString; Json::Value ret; From 42373443b6f94fbca321e3af4b0daf0276b5dc05 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 13 May 2024 18:58:55 +0000 Subject: [PATCH 09/11] #1876 Update unit test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 22ab39c8f..93c790ce8 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -2898,20 +2898,19 @@ BOOST_AUTO_TEST_CASE( deploy_controller_generation2 ) { BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { + // Inserting ConfigController mockup into config and enabling flexibleDeploymentPatch. + // ConfigController mockup contract: + // pragma solidity ^0.8.9; - // contract ConfigController { // bool public freeContractDeployment = false; - // function isAddressWhitelisted(address addr) external view returns (bool) { // return false; // } - // function isDeploymentAllowed(address origin, address sender) // external view returns (bool) { // return freeContractDeployment; // } - // function setFreeContractDeployment() external { // freeContractDeployment = true; // } @@ -2967,6 +2966,7 @@ BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { "8fb480406fc2728a960029"; + // Trying to deploy contract without permission Json::Value deployContractWithoutRoleTx; deployContractWithoutRoleTx["from"] = senderAddress.hex(); deployContractWithoutRoleTx["code"] = compiled; @@ -2983,7 +2983,7 @@ BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { fixture.rpcClient->eth_getCode( receipt["contractAddress"].asString(), "latest" ); BOOST_REQUIRE( code.asString() == "0x" ); - // Allow deploy by calling setFreeContractDeployment() + // Allow to deploy by calling setFreeContractDeployment() Json::Value grantDeployerRoleTx; grantDeployerRoleTx["data"] = "0xf7e2a91b"; grantDeployerRoleTx["from"] = senderAddress.hex(); @@ -2994,6 +2994,7 @@ BOOST_AUTO_TEST_CASE( deployment_control_v2 ) { BOOST_REQUIRE( !txHash.empty() ); dev::eth::mineTransaction( *( fixture.client ), 1 ); + // Deploying with permission Json::Value deployContractTx; deployContractTx["from"] = senderAddress.hex(); deployContractTx["code"] = compiled; From 03900a6b6972f732e86d470ab231f8ab1a3510e5 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 13 May 2024 20:02:40 +0000 Subject: [PATCH 10/11] #1876 Add comments --- libethereum/Executive.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index f1b46c440..242245ba7 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -469,17 +469,18 @@ bool Executive::go( OnOpFunc const& _onOp ) { // Create VM instance. Force Interpreter if tracing requested. auto vm = VMFactory::create(); if ( m_isCreation ) { - bytes in; + // Checking whether deployment is allowed via ConfigController contract + bytes calldata; if ( FlexibleDeploymentPatch::isEnabledWhen( m_envInfo.committedBlockTimestamp() ) ) { - in = isDeploymentAllowedCallData( m_ext->origin, m_ext->caller ); + calldata = isDeploymentAllowedCallData( m_ext->origin, m_ext->caller ); } else { - in = isAddressWhitelistedCallData( m_ext->caller ); + calldata = isAddressWhitelistedCallData( m_ext->caller ); } unique_ptr< CallParameters > deploymentCallParams( new CallParameters( SystemAddress, c_configControllerContractAddress, c_configControllerContractAddress, 0, 0, m_gas, - bytesConstRef( in.data(), in.size() ), {} ) ); + bytesConstRef( calldata.data(), calldata.size() ), {} ) ); auto deploymentCallResult = m_ext->call( *deploymentCallParams ); auto deploymentCallOutput = dev::toHex( deploymentCallResult.output ); if ( !deploymentCallOutput.empty() && u256( deploymentCallOutput ) == 0 ) { From aa957df51151f43775aa7a2bfa088e98e777c47b Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Tue, 14 May 2024 11:26:04 +0000 Subject: [PATCH 11/11] #1876 Update comments --- libethcore/Common.cpp | 4 ++-- libethcore/Common.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index 678846e46..cb889a51a 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -109,7 +109,7 @@ std::string formatBalance( bigint const& _b ) { } bytes isAddressWhitelistedCallData( Address const& _deployer ) { - // Generating calldata for isAddressWhitelisted call to ConfigController smart contract: + // Generating calldata for isAddressWhitelisted contract call: // 13f44d1 - selector of isAddressWhitelisted function // 000000000000000000000000 - 12-byte offset for sender address // _deployer - 20-byte sender address @@ -118,7 +118,7 @@ bytes isAddressWhitelistedCallData( Address const& _deployer ) { } bytes isDeploymentAllowedCallData( Address const& _origin, Address const& _deployer ) { - // Generating calldata for isDeploymentAllowed call to ConfigController smart contract: + // Generating calldata for isDeploymentAllowed contract call: // d0f557f4 - selector of isDeploymentAllowed function // 000000000000000000000000 - 12-byte offset for origin address // _origin - 20-byte origin address diff --git a/libethcore/Common.h b/libethcore/Common.h index 2fd143b93..b48b5ffd4 100644 --- a/libethcore/Common.h +++ b/libethcore/Common.h @@ -58,10 +58,10 @@ extern const bytes c_blockhashContractCode; /// Address of the special contract for deployment control extern const Address c_configControllerContractAddress; -/// Formatting call data for deployment control contract +/// Generating call data for deployment control contract bytes isAddressWhitelistedCallData( Address const& _deployer ); -/// Formatting call data for deployment control contract, considering tx origin +/// Generating calldata for deployment control contract, considering tx origin bytes isDeploymentAllowedCallData( Address const& _origin, Address const& _deployer ); /// Formatting call data for multitransaction contract