Skip to content

Commit

Permalink
Merge pull request #1868 from skalenetwork/enhancement/SKALED-1583-pa…
Browse files Browse the repository at this point in the history
…tch-architecture-plus-17.2

Enhancement/skaled 1583 patch architecture plus 17.2
  • Loading branch information
dimalit authored Apr 17, 2024
2 parents d237b0f + 62b56b3 commit 913844f
Show file tree
Hide file tree
Showing 94 changed files with 1,234 additions and 1,090 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.19.0
3.19.0
6 changes: 4 additions & 2 deletions libdevcore/JsonUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ std::string dev::jsonTypeAsString( json_spirit::Value_type _type ) {
}

void dev::requireJsonFields( json_spirit::mObject const& _o, std::string const& _config,
std::map< std::string, JsonFieldOptions > const& _validationMap ) {
std::map< std::string, JsonFieldOptions > const& _validationMap,
std::function< bool( const std::string& ) > _callbackForUnexpected ) {
// check for unexpected fiedls
for ( auto const& field : _o ) {
if ( !_validationMap.count( field.first ) ) {
// _callbackForUnexpected allows to accept ertain unexpected fields
if ( !_validationMap.count( field.first ) && !_callbackForUnexpected( field.first ) ) {
std::string const comment =
"Unexpected field '" + field.first + "' in config: " + _config;
cerror << comment << "\n"
Expand Down
8 changes: 6 additions & 2 deletions libdevcore/JsonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ using JsonFieldOptions = std::pair< JsonTypeSet, JsonFieldPresence >;
@param _validationMap a map with json objects that would be checked. "objName" -> {js::str_type,
jsonField::Required}
*/
void requireJsonFields( json_spirit::mObject const& _o, std::string const& _configName,
std::map< std::string, JsonFieldOptions > const& _validationMap );
void requireJsonFields(
json_spirit::mObject const& _o, std::string const& _configName,
std::map< std::string, JsonFieldOptions > const& _validationMap,
std::function< bool( const std::string& ) > _callbackForUnexpected = []( const std::string& ) {
return false;
} );
} // namespace dev
2 changes: 1 addition & 1 deletion libdevcore/LevelDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include <leveldb/write_batch.h>
#include <boost/filesystem.hpp>

#include "shared_mutex"
#include <secp256k1_sha256.h>
#include <shared_mutex>

namespace dev::db {
class LevelDB : public DatabaseFace {
Expand Down
12 changes: 0 additions & 12 deletions libethashseal/Ethash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,6 @@ void Ethash::verify( Strictness _s, BlockHeader const& _bi, BlockHeader const& _
}
}

void Ethash::verifyTransaction( ImportRequirements::value _ir, TransactionBase const& _t,
BlockHeader const& _header, u256 const& _startGasUsed ) const {
SealEngineFace::verifyTransaction( _ir, _t, _header, _startGasUsed );

if ( _ir & ImportRequirements::TransactionSignatures ) {
if ( _header.number() >= chainParams().EIP158ForkBlock ) {
uint64_t chainID = chainParams().chainID;
_t.checkChainId( chainID, chainParams().skaleDisableChainIdCheck );
} // if
}
}

u256 Ethash::childGasLimit( BlockHeader const& _bi, u256 const& _gasFloorTarget ) const {
u256 gasFloorTarget = _gasFloorTarget == Invalid256 ? 3141562 : _gasFloorTarget;
u256 gasLimit = _bi.gasLimit();
Expand Down
2 changes: 0 additions & 2 deletions libethashseal/Ethash.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class Ethash : public SealEngineBase {
StringHashMap jsInfo( BlockHeader const& _bi ) const override;
void verify( Strictness _s, BlockHeader const& _bi, BlockHeader const& _parent,
bytesConstRef _block ) const override;
void verifyTransaction( ImportRequirements::value _ir, TransactionBase const& _t,
BlockHeader const& _header, u256 const& _startGasUsed ) const override;
void populateFromParent( BlockHeader& _bi, BlockHeader const& _parent ) const override;

strings sealers() const override;
Expand Down
83 changes: 47 additions & 36 deletions libethcore/ChainOperationParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/

#include "ChainOperationParams.h"

#include <libethereum/SchainPatch.h>

#include <libdevcore/CommonData.h>
#include <libdevcore/Log.h>

Expand All @@ -42,6 +45,14 @@ PrecompiledContract::PrecompiledContract( unsigned _base, unsigned _word,
},
_exec, _startingBlock, _allowedAddresses ) {}

time_t SChain::getPatchTimestamp( SchainPatchEnum _patchEnum ) const {
assert( _patchEnum < SchainPatchEnum::PatchesCount );
if ( _patchEnum < SchainPatchEnum::PatchesCount )
return _patchTimestamps[static_cast< size_t >( _patchEnum )];
else
return 0;
}

ChainOperationParams::ChainOperationParams()
: m_blockReward( "0x4563918244F40000" ),
minGasLimit( 0x1388 ),
Expand All @@ -52,43 +63,33 @@ ChainOperationParams::ChainOperationParams()
difficultyBoundDivisor( 0x0800 ),
durationLimit( 0x0d ) {}

EVMSchedule const& ChainOperationParams::scheduleForBlockNumber( u256 const& _blockNumber ) const {
if ( _blockNumber >= skaleUnlimitedForkBlock )
return SkaleSchedule_Unlimited;
else if ( _blockNumber >= skale1024ForkBlock )
return SkaleSchedule_1024k;
else if ( _blockNumber >= skale512ForkBlock )
return SkaleSchedule_512k;
else if ( _blockNumber >= skale256ForkBlock )
return SkaleSchedule_256k;
else if ( _blockNumber >= skale128ForkBlock )
return SkaleSchedule_128k;
else if ( _blockNumber >= skale64ForkBlock )
return SkaleSchedule_64k;
else if ( _blockNumber >= skale32ForkBlock )
return SkaleSchedule_32k;
else if ( _blockNumber >= skale16ForkBlock )
return SkaleSchedule_16k;
else if ( _blockNumber >= experimentalForkBlock )
return ExperimentalSchedule;
else if ( _blockNumber >= istanbulForkBlock )
return IstanbulSchedule;
else if ( _blockNumber >= constantinopleFixForkBlock )
return ConstantinopleFixSchedule;
else if ( _blockNumber >= constantinopleForkBlock )
return ConstantinopleSchedule;
else if ( _blockNumber >= eWASMForkBlock )
return EWASMSchedule;
else if ( _blockNumber >= byzantiumForkBlock )
return ByzantiumSchedule;
else if ( _blockNumber >= EIP158ForkBlock )
return EIP158Schedule;
else if ( _blockNumber >= EIP150ForkBlock )
return EIP150Schedule;
else if ( _blockNumber >= homesteadForkBlock )
return HomesteadSchedule;
EVMSchedule const ChainOperationParams::makeEvmSchedule(
time_t _committedBlockTimestamp, u256 const& _workingBlockNumber ) const {
EVMSchedule result;

// 1 decide by block number
if ( _workingBlockNumber >= experimentalForkBlock )
result = ExperimentalSchedule;
else if ( _workingBlockNumber >= istanbulForkBlock )
result = IstanbulSchedule;
else if ( _workingBlockNumber >= constantinopleFixForkBlock )
result = ConstantinopleFixSchedule;
else if ( _workingBlockNumber >= constantinopleForkBlock )
result = ConstantinopleSchedule;
else if ( _workingBlockNumber >= byzantiumForkBlock )
result = ByzantiumSchedule;
else if ( _workingBlockNumber >= EIP158ForkBlock )
result = EIP158Schedule;
else if ( _workingBlockNumber >= EIP150ForkBlock )
result = EIP150Schedule;
else
return FrontierSchedule;
result = HomesteadSchedule;

// 2 based on previous - decide by timestamp
if ( PushZeroPatch::isEnabledWhen( _committedBlockTimestamp ) )
result = PushZeroPatch::makeSchedule( result );

return result;
}

u256 ChainOperationParams::blockReward( EVMSchedule const& _schedule ) const {
Expand All @@ -98,6 +99,16 @@ u256 ChainOperationParams::blockReward( EVMSchedule const& _schedule ) const {
return m_blockReward;
}

u256 ChainOperationParams::blockReward(
time_t _committedBlockTimestamp, u256 const& _workingBlockNumber ) const {
EVMSchedule const& schedule{ makeEvmSchedule( _committedBlockTimestamp, _workingBlockNumber ) };
return blockReward( schedule );
}

void ChainOperationParams::setBlockReward( u256 const& _newBlockReward ) {
m_blockReward = _newBlockReward;
}

time_t ChainOperationParams::getPatchTimestamp( SchainPatchEnum _patchEnum ) const {
return sChain.getPatchTimestamp( _patchEnum );
}
39 changes: 28 additions & 11 deletions libethcore/ChainOperationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <libdevcore/Common.h>
#include <libethereum/Precompiled.h>
#include <libethereum/SchainPatchEnum.h>

#include "libethcore/Common.h"
#include "libethcore/EVMSchedule.h"
Expand Down Expand Up @@ -173,16 +174,12 @@ struct SChain {
int emptyBlockIntervalMs = -1;
int64_t levelDBReopenIntervalMs = -1;
size_t t = 1;
time_t revertableFSPatchTimestamp = 0;
time_t contractStoragePatchTimestamp = 0;
time_t contractStorageZeroValuePatchTimestamp = 0;
time_t verifyDaSigsPatchTimestamp = 0;
time_t storageDestructionPatchTimestamp = 0;
time_t powCheckPatchTimestamp = 0;
time_t precompiledConfigPatchTimestamp = 0;
time_t pushZeroPatchTimestamp = 0;
time_t skipInvalidTransactionsPatchTimestamp = 0;
time_t correctForkInPowPatchTimestamp = 0;

// key is patch name
// public - for tests, don't access it directly
std::vector< time_t > _patchTimestamps =
std::vector< time_t >( static_cast< int >( SchainPatchEnum::PatchesCount ) );
time_t getPatchTimestamp( SchainPatchEnum _patchEnum ) const;

SChain() {
name = "TestChain";
Expand Down Expand Up @@ -210,8 +207,10 @@ struct ChainOperationParams {
u256 m_blockReward;

public:
EVMSchedule const& scheduleForBlockNumber( u256 const& _blockNumber ) const;
EVMSchedule const makeEvmSchedule(
time_t _committedBlockTimestamp, u256 const& _workingBlockNumber ) const;
u256 blockReward( EVMSchedule const& _schedule ) const;
u256 blockReward( time_t _committedBlockTimestamp, u256 const& _workingBlockNumber ) const;
void setBlockReward( u256 const& _newBlockReward );
u256 maximumExtraDataSize = 1024;
u256 accountStartNonce = 0;
Expand Down Expand Up @@ -257,6 +256,24 @@ struct ChainOperationParams {
u256 externalGasDifficulty = ~u256( 0 );
typedef std::vector< std::string > vecAdminOrigins_t;
vecAdminOrigins_t vecAdminOrigins; // wildcard based folters for IP addresses

time_t getPatchTimestamp( SchainPatchEnum _patchEnum ) const;

bool isPrecompiled( Address const& _a, u256 const& _blockNumber ) const {
return precompiled.count( _a ) != 0 && _blockNumber >= precompiled.at( _a ).startingBlock();
}
bigint costOfPrecompiled(
Address const& _a, bytesConstRef _in, u256 const& _blockNumber ) const {
return precompiled.at( _a ).cost( _in, *this, _blockNumber );
}
std::pair< bool, bytes > executePrecompiled(
Address const& _a, bytesConstRef _in, u256 const& ) const {
return precompiled.at( _a ).execute( _in );
}
bool precompiledExecutionAllowedFrom(
Address const& _a, Address const& _from, bool _readOnly ) const {
return precompiled.at( _a ).executionAllowedFrom( _from, _readOnly );
}
};

} // namespace eth
Expand Down
62 changes: 1 addition & 61 deletions libethcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct EVMSchedule {
bool haveExtcodehash = false;
bool haveChainID = false;
bool haveSelfbalance = false;
bool havePush0 = false;
std::array< unsigned, 8 > tierStepGas;
unsigned expGas = 10;
unsigned expByteGas = 10;
Expand Down Expand Up @@ -93,7 +94,6 @@ struct EVMSchedule {
};

static const EVMSchedule DefaultSchedule = EVMSchedule();
static const EVMSchedule FrontierSchedule = EVMSchedule( false, false, 21000 );
static const EVMSchedule HomesteadSchedule = EVMSchedule( true, true, 53000 );

static const EVMSchedule EIP150Schedule = [] {
Expand Down Expand Up @@ -125,12 +125,6 @@ static const EVMSchedule ByzantiumSchedule = [] {
return schedule;
}();

static const EVMSchedule EWASMSchedule = [] {
EVMSchedule schedule = ByzantiumSchedule;
schedule.maxCodeSize = std::numeric_limits< unsigned >::max();
return schedule;
}();

static const EVMSchedule ConstantinopleSchedule = [] {
EVMSchedule schedule = ByzantiumSchedule;
schedule.haveCreate2 = true;
Expand Down Expand Up @@ -174,60 +168,6 @@ static const EVMSchedule ExperimentalSchedule = [] {
return schedule;
}();

static const EVMSchedule SkaleSchedule_base = [] {
EVMSchedule schedule = ConstantinopleSchedule;
return schedule;
}();

static const EVMSchedule SkaleSchedule_16k = [] {
EVMSchedule schedule = SkaleSchedule_base;
schedule.maxCodeSize = 1024 * 16;
return schedule;
}();

static const EVMSchedule SkaleSchedule_32k = [] {
EVMSchedule schedule = SkaleSchedule_base;
schedule.maxCodeSize = 1024 * 32;
return schedule;
}();

static const EVMSchedule SkaleSchedule_64k = [] {
EVMSchedule schedule = SkaleSchedule_base;
schedule.maxCodeSize = 1024 * 64;
return schedule;
}();

static const EVMSchedule SkaleSchedule_128k = [] {
EVMSchedule schedule = SkaleSchedule_base;
schedule.maxCodeSize = 1024 * 128;
return schedule;
}();

static const EVMSchedule SkaleSchedule_256k = [] {
EVMSchedule schedule = SkaleSchedule_base;
schedule.maxCodeSize = 1024 * 256;
return schedule;
}();

static const EVMSchedule SkaleSchedule_512k = [] {
EVMSchedule schedule = SkaleSchedule_base;
schedule.maxCodeSize = 1024 * 512;
return schedule;
}();

static const EVMSchedule SkaleSchedule_1024k = [] {
EVMSchedule schedule = SkaleSchedule_base;
schedule.maxCodeSize = 1024 * 1024;
return schedule;
}();

static const EVMSchedule SkaleSchedule_Unlimited = [] {
EVMSchedule schedule = SkaleSchedule_base;
schedule.maxCodeSize = std::numeric_limits< unsigned >::max();
return schedule;
}();


inline EVMSchedule const& latestScheduleForAccountVersion( u256 const& _version ) {
if ( _version == 0 )
return IstanbulSchedule;
Expand Down
Loading

0 comments on commit 913844f

Please sign in to comment.