Skip to content

[ETCM-20] Repricing for trie-size-dependent opcodes #648

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/scala/io/iohk/ethereum/vm/EvmConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ object FeeSchedule {

class AghartaFeeSchedule extends ByzantiumFeeSchedule

class PhoenixFeeSchedule extends AghartaFeeSchedule
class PhoenixFeeSchedule extends AghartaFeeSchedule{
override val G_sload: BigInt = 800
override val G_balance: BigInt = 700
}

}

Expand Down
9 changes: 8 additions & 1 deletion src/main/scala/io/iohk/ethereum/vm/OpCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ object OpCodes {
List(EXTCODEHASH, CREATE2, SHL, SHR, SAR) ++ ByzantiumOpCodes

val PhoenixOpCodes: List[OpCode] =
List(CHAINID) ++ ConstantinopleOpCodes
List(CHAINID, SELFBALANCE) ++ ConstantinopleOpCodes
}

object OpCode {
Expand Down Expand Up @@ -1157,3 +1157,10 @@ case object SELFDESTRUCT extends OpCode(0xff, 1, 0, _.G_selfdestruct) {
}

case object CHAINID extends ConstOp(0x46)(state => UInt256(state.env.evmConfig.blockchainConfig.chainId))

case object SELFBALANCE extends OpCode(0x47, 0, 1, _.G_low) with ConstGas {
protected def exec[W <: WorldStateProxy[W, S], S <: Storage[S]](state: ProgramState[W, S]): ProgramState[W, S] = {
val stack2 = state.stack.push(state.ownBalance)
state.withStack(stack2).step()
}
}
2 changes: 1 addition & 1 deletion src/test/scala/io/iohk/ethereum/vm/Generators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ object Generators extends ObjectGenerators {
inputDataGen: Gen[ByteString] = getByteStringGen(0, 0),
valueGen: Gen[UInt256] = getUInt256Gen(),
blockNumberGen: Gen[UInt256] = getUInt256Gen(0, 300),
evmConfig: EvmConfig = EvmConfig.ConstantinopleConfigBuilder(blockchainConfig),
evmConfig: EvmConfig = EvmConfig.PhoenixConfigBuilder(blockchainConfig),
returnDataGen: Gen[ByteString] = getByteStringGen(0, 0)
): Gen[PS] =
for {
Expand Down
10 changes: 10 additions & 0 deletions src/test/scala/io/iohk/ethereum/vm/OpCodeFunSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,16 @@ class OpCodeFunSpec extends FunSuite with OpCodeTesting with Matchers with Prope
}
}

test(SELFBALANCE) { op =>
forAll(getProgramStateGen()) { stateIn =>
val stateOut = executeOp(op, stateIn)
val balance = stateOut.ownBalance
withStackVerification(op, stateIn, stateOut) {
stateOut shouldEqual stateIn.withStack(stateIn.stack.push(balance)).step()
}
}
}

verifyAllOpCodesRegistered(except = CREATE, CREATE2, CALL, CALLCODE, DELEGATECALL, STATICCALL, SHL, SHR, SAR)

test("sliceBytes helper") {
Expand Down
5 changes: 3 additions & 2 deletions src/test/scala/io/iohk/ethereum/vm/OpCodeGasSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.scalacheck.Gen

class OpCodeGasSpec extends FunSuite with OpCodeTesting with Matchers with PropertyChecks {

override val config = EvmConfig.ConstantinopleConfigBuilder(blockchainConfig)
override val config = EvmConfig.PhoenixConfigBuilder(blockchainConfig)

import config.feeSchedule._

Expand Down Expand Up @@ -61,7 +61,8 @@ class OpCodeGasSpec extends FunSuite with OpCodeTesting with Matchers with Prope
JUMPDEST -> G_jumpdest,
SHL -> G_verylow,
SHR -> G_verylow,
SAR -> G_verylow
SAR -> G_verylow,
SELFBALANCE -> G_low
) ++ stackOpsFees ++ constOpsFees


Expand Down