Skip to content

Commit

Permalink
Merge branch 'develop' into bug/IS-879-invalid-receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroNazarenko authored Nov 3, 2023
2 parents 7ba33e3 + b4b996a commit ad847ed
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
1 change: 1 addition & 0 deletions libethcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ target_include_directories( ethcore PRIVATE
target_link_libraries( ethcore PUBLIC
devcrypto
devcore
skale
)
21 changes: 16 additions & 5 deletions libethcore/SealEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "SealEngine.h"
#include "TransactionBase.h"

#include <libskale/POWCheckPatch.h>

#include "../libdevcore/microprofile.h"

using namespace std;
Expand Down Expand Up @@ -94,6 +96,16 @@ void SealEngineFace::populateFromParent( BlockHeader& _bi, BlockHeader const& _p

void SealEngineFace::verifyTransaction( ImportRequirements::value _ir, TransactionBase const& _t,
BlockHeader const& _header, u256 const& _gasUsed ) const {
// verifyTransaction is the only place where TransactionBase is used instead of Transaction.
u256 gas;
if ( POWCheckPatch::isEnabled() ) {
// new behavior is to use pow-enabled gas
gas = _t.gas();
} else {
// old behavior is to use non-POW gas
gas = _t.nonPowGas();
}

MICROPROFILE_SCOPEI( "SealEngineFace", "verifyTransaction", MP_ORCHID );
if ( ( _ir & ImportRequirements::TransactionSignatures ) &&
_header.number() < chainParams().EIP158ForkBlock && _t.isReplayProtected() )
Expand All @@ -118,17 +130,16 @@ void SealEngineFace::verifyTransaction( ImportRequirements::value _ir, Transacti
eth::EVMSchedule const& schedule = evmSchedule( _header.number() );

// Pre calculate the gas needed for execution
if ( ( _ir & ImportRequirements::TransactionBasic ) &&
_t.baseGasRequired( schedule ) > _t.gas() )
if ( ( _ir & ImportRequirements::TransactionBasic ) && _t.baseGasRequired( schedule ) > gas )
BOOST_THROW_EXCEPTION( OutOfGasIntrinsic() << RequirementError(
static_cast< bigint >( _t.baseGasRequired( schedule ) ),
static_cast< bigint >( _t.gas() ) ) );
static_cast< bigint >( gas ) ) );

// Avoid transactions that would take us beyond the block gas limit.
if ( _gasUsed + static_cast< bigint >( _t.gas() ) > _header.gasLimit() )
if ( _gasUsed + static_cast< bigint >( gas ) > _header.gasLimit() )
BOOST_THROW_EXCEPTION( BlockGasLimitReached() << RequirementErrorComment(
static_cast< bigint >( _header.gasLimit() - _gasUsed ),
static_cast< bigint >( _t.gas() ),
static_cast< bigint >( gas ),
string( "_gasUsed + (bigint)_t.gas() > _header.gasLimit()" ) ) );
}

Expand Down
12 changes: 12 additions & 0 deletions libethcore/TransactionBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ u256 TransactionBase::gasPrice() const {
}

u256 TransactionBase::gas() const {
/* Note that gas() function has been removed from Transaction.
* instead the logic has been moved to the gas() function of TransactionBase
* this has been done in order to address the problem of switching "virtual" on/off
*/
assert( !isInvalid() );
if ( getExternalGas() != 0 ) {
return getExternalGas();
} else {
return m_gas;
}
}

u256 TransactionBase::nonPowGas() const {
return m_gas;
}
14 changes: 13 additions & 1 deletion libethcore/TransactionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@ class TransactionBase {
/// @returns the base fee and thus the implied exchange rate of ETH to GAS.
u256 gasPrice() const;

/// @returns the non-PoW gas
u256 nonPowGas() const;

/// @returns the total gas to convert, paid for from sender's account. Any unused gas gets
/// refunded once the contract is ended.
virtual u256 gas() const;
u256 gas() const;

/// @returns the receiving address of the message-call transaction (undefined for
/// contract-creation transactions).
Expand Down Expand Up @@ -261,6 +264,15 @@ class TransactionBase {

static bool isZeroSignature( u256 const& _r, u256 const& _s ) { return !_r && !_s; }

/*
* this function is provided in order for aleth tests and utilities to compile.
* In will never be called in skaled since in skaled TransactionBase objects are never
* instantiated. Aleth tests and utilities do instantiate TransactionBase
*
* The function always returns zero, which means no PoW.
*/
virtual u256 getExternalGas() const { return 0; }

/// Clears the signature.
void clearSignature() { m_vrs = SignatureStruct(); }

Expand Down
11 changes: 1 addition & 10 deletions libethereum/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <libdevcrypto/Common.h>
#include <libethcore/Exceptions.h>
#include <libevm/VMFace.h>
#include <libskale/POWCheckPatch.h>

using namespace std;
using namespace dev;
Expand Down Expand Up @@ -166,21 +165,13 @@ bool Transaction::hasExternalGas() const {
}

u256 Transaction::getExternalGas() const {
if ( hasExternalGas() ) {
if ( m_externalGasIsChecked && hasExternalGas() ) {
return *m_externalGas;
} else {
return u256( 0 );
}
}

u256 Transaction::gas() const {
if ( m_externalGasIsChecked && hasExternalGas() && POWCheckPatch::isEnabled() ) {
return *m_externalGas;
} else {
return TransactionBase::gas();
}
}

u256 Transaction::gasPrice() const {
if ( m_externalGasIsChecked && hasExternalGas() ) {
return 0;
Expand Down
2 changes: 0 additions & 2 deletions libethereum/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ class Transaction : public TransactionBase {

u256 getExternalGas() const;

u256 gas() const;

u256 gasPrice() const;

void checkOutExternalGas( u256 const& _difficulty );
Expand Down

0 comments on commit ad847ed

Please sign in to comment.