Skip to content

Commit

Permalink
Merge pull request #3 from rootstock/fix_staticcall
Browse files Browse the repository at this point in the history
RSKIP 103
  • Loading branch information
diega authored Jan 3, 2019
2 parents d6189b8 + b073f7a commit 0762aef
Show file tree
Hide file tree
Showing 19 changed files with 222 additions and 33 deletions.
2 changes: 0 additions & 2 deletions rskj-core/src/main/java/co/rsk/db/ContractDetailsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package co.rsk.db;

import co.rsk.crypto.Keccak256;
import co.rsk.panic.PanicProcessor;
import co.rsk.trie.*;
import com.google.common.annotations.VisibleForTesting;
import org.ethereum.crypto.Keccak256Helper;
Expand Down Expand Up @@ -47,7 +46,6 @@
* Created by ajlopez on 05/04/2017.
*/
public class ContractDetailsImpl implements ContractDetails {
private static final PanicProcessor panicProcessor = new PanicProcessor();
private static final Logger logger = LoggerFactory.getLogger("contractdetails");

private Trie trie;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ private static boolean addressIsDedicated(byte[] address) {

RskAddress addr = new RskAddress(address);

if (addr.equals(PrecompiledContracts.REMASC_ADDR) ||
addr.equals(PrecompiledContracts.BRIDGE_ADDR)) {
return true;
}

return false;
return addr.equals(PrecompiledContracts.REMASC_ADDR) || addr.equals(PrecompiledContracts.BRIDGE_ADDR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public interface BlockchainConfig {

boolean isRskip91();

boolean isRskip103();

boolean isRskip87();

boolean isRskip92();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.util.List;

import static java.util.Arrays.asList;
import static org.ethereum.datasource.DataSourcePool.levelDbByName;

@Configuration
@ComponentScan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public boolean isRskip88() {
@Override
public boolean isRskip91() { return false; }

@Override
public boolean isRskip103() { return false; }

@Override
public boolean isRskip87() { return false; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,34 @@

public class HardForkActivationConfig {
private final int orchidActivationHeight;
private final int orchid060ActivationHeight;

private static final String PROPERTY_ORCHID_NAME = "orchid";
private static final String PROPERTY_ORCHID_060_NAME = "orchid060";

public HardForkActivationConfig(Config config) {
// If I don't have any config for orchidActivationHeight I will set it to 0
this(config.hasPath(PROPERTY_ORCHID_NAME) ? config.getInt(PROPERTY_ORCHID_NAME) : 0);
this(
config.hasPath(PROPERTY_ORCHID_NAME) ? config.getInt(PROPERTY_ORCHID_NAME) : 0,
config.hasPath(PROPERTY_ORCHID_060_NAME) ? config.getInt(PROPERTY_ORCHID_060_NAME) : 0
);
}

public HardForkActivationConfig(int orchidActivationHeight) {
public HardForkActivationConfig(int orchidActivationHeight, int orchid060ActivationHeight) {
this.orchidActivationHeight = orchidActivationHeight;
this.orchid060ActivationHeight = orchid060ActivationHeight;
}

public int getOrchidActivationHeight() {
return orchidActivationHeight;
}

/**
* TODO(mc): Only Devnet knows about Orchid060 activation config.
* This is a quick solution but the whole HF activation needs work.
* E.g. we don't handle the case where Orchid060 < Orchid (fails at runtime).
*/
public int getOrchid060ActivationHeight() {
return orchid060ActivationHeight;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of RskJ
* Copyright (C) 2018 RSK Labs Ltd.
* (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.ethereum.config.blockchain.devnet;

public class DevNetOrchid060Config extends DevNetOrchidConfig {
@Override
public boolean isRskip103() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of RskJ
* Copyright (C) 2018 RSK Labs Ltd.
* (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.ethereum.config.blockchain.mainnet;

public class MainNetOrchid060Config extends MainNetOrchidConfig {
@Override
public boolean isRskip103() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public boolean isRskip91() {
return true;
}

@Override
public boolean isRskip103() {
return true;
}

@Override
public boolean isRskip87() { return true; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of RskJ
* Copyright (C) 2018 RSK Labs Ltd.
* (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.ethereum.config.blockchain.testnet;

public class TestNetOrchid060Config extends TestNetDifficultyDropEnabledConfig {

@Override
public boolean isRskip103() {
return true;
}
}
15 changes: 10 additions & 5 deletions rskj-core/src/main/java/org/ethereum/config/net/DevNetConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
package org.ethereum.config.net;

import org.ethereum.config.blockchain.HardForkActivationConfig;
import org.ethereum.config.blockchain.devnet.DevNetOrchidConfig;
import org.ethereum.config.blockchain.devnet.DevNetGenesisConfig;
import org.ethereum.config.blockchain.devnet.DevNetOrchid060Config;
import org.ethereum.config.blockchain.devnet.DevNetOrchidConfig;


/**
Expand All @@ -45,11 +46,15 @@ public static DevNetConfig getFromConfig(HardForkActivationConfig hardForkActiva
return getDefaultDevNetConfig();
}
DevNetConfig customConfig = new DevNetConfig();
if (hardForkActivationConfig.getOrchidActivationHeight() != 0) {
// Only add genesis config if the fork configs are set
customConfig.add(0, new DevNetGenesisConfig());
if (hardForkActivationConfig.getOrchid060ActivationHeight() != 0) {
if (hardForkActivationConfig.getOrchidActivationHeight() != 0) {
customConfig.add(0, new DevNetGenesisConfig());
}

customConfig.add(hardForkActivationConfig.getOrchidActivationHeight(), new DevNetOrchidConfig());
}
customConfig.add(hardForkActivationConfig.getOrchidActivationHeight(), new DevNetOrchidConfig());

customConfig.add(hardForkActivationConfig.getOrchid060ActivationHeight(), new DevNetOrchid060Config());
return customConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.ethereum.config.blockchain.mainnet.MainNetAfterBridgeSyncConfig;
import org.ethereum.config.blockchain.mainnet.MainNetBeforeBridgeSyncConfig;
import org.ethereum.config.blockchain.mainnet.MainNetOrchid060Config;
import org.ethereum.config.blockchain.mainnet.MainNetOrchidConfig;


Expand All @@ -34,5 +35,6 @@ public MainNetConfig() {
// On blockchain launch blocks will be faster until difficulty is adjusted to available hashing power.
add(370_000, new MainNetAfterBridgeSyncConfig());
add(729_000, new MainNetOrchidConfig());
add(1_052_700, new MainNetOrchid060Config());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.ethereum.config.blockchain.testnet.TestNetBeforeBridgeSyncConfig;
import org.ethereum.config.blockchain.testnet.TestNetDifficultyDropEnabledConfig;
import org.ethereum.config.blockchain.testnet.TestNetOrchid060Config;

public class TestNetConfig extends AbstractNetConfig {
public static final TestNetConfig INSTANCE = new TestNetConfig();
Expand All @@ -31,5 +32,7 @@ public TestNetConfig() {
// 21 days of 1 block every 14 seconds.
// On blockchain launch blocks will be faster until difficulty is adjusted to available hashing power.
add(114_000, new TestNetDifficultyDropEnabledConfig());
// Static call fix.
add(233_000, new TestNetOrchid060Config());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.slf4j.Logger;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.ConcurrentHashMap;
Expand Down
2 changes: 0 additions & 2 deletions rskj-core/src/main/java/org/ethereum/rpc/LogFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import org.ethereum.db.TransactionInfo;
import org.ethereum.vm.LogInfo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static org.ethereum.rpc.TypeConverter.stringHexToByteArray;

Expand Down
27 changes: 21 additions & 6 deletions rskj-core/src/main/java/org/ethereum/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import co.rsk.config.VmConfig;
import co.rsk.core.RskAddress;
import org.ethereum.core.Blockchain;
import org.ethereum.crypto.HashUtil;
import org.ethereum.config.BlockchainConfig;
import org.ethereum.db.ContractDetails;
Expand Down Expand Up @@ -1411,8 +1410,17 @@ protected void doCALL(){
DataWord gas = program.stackPop();
DataWord codeAddress = program.stackPop();

// value is always zero in a DELEGATECALL operation
DataWord value = op.equals(OpCode.DELEGATECALL) ? DataWord.ZERO : program.stackPop();
DataWord value;

BlockchainConfig config = program.getBlockchainConfig();

if (config.isRskip103()) {
// value is always zero in a DELEGATECALL or STATICCALL operation
value = op == OpCode.DELEGATECALL || op == OpCode.STATICCALL ? DataWord.ZERO : program.stackPop();
} else {
// value is always zero in a DELEGATECALL operation
value = op == OpCode.DELEGATECALL ? DataWord.ZERO : program.stackPop();
}

if (program.isStaticCall() && op == CALL && !value.isZero()) {
throw Program.ExceptionHelper.modificationException();
Expand Down Expand Up @@ -1484,8 +1492,14 @@ protected void doCALL(){
program.disposeWord(outDataSize);
program.disposeWord(codeAddress);
program.disposeWord(gas);
if (!op.equals(OpCode.DELEGATECALL)) {
program.disposeWord(value);
if (config.isRskip103()) {
if (op != OpCode.DELEGATECALL && op != OpCode.STATICCALL) {
program.disposeWord(value);
}
} else {
if (!op.equals(OpCode.DELEGATECALL)) {
program.disposeWord(value);
}
}

program.step();
Expand Down Expand Up @@ -1515,7 +1529,8 @@ private long computeCallGas(DataWord codeAddress,
callGas += GasCost.NEW_ACCT_CALL;
}

if (op != OpCode.DELEGATECALL && !value.isZero()) {
// RSKIP103: we don't need to check static call nor delegate call since value will always be zero
if (!value.isZero()) {
callGas += GasCost.VT_CALL;
}

Expand Down
9 changes: 7 additions & 2 deletions rskj-core/src/main/java/org/ethereum/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,16 @@ public void stackPush(DataWord stackWord) {
}

public void disposeWord(DataWord dw) {
if (dataWordPool==null) {
if (dataWordPool == null) {
return ;
}

if (dw == DataWord.ZERO || dw == DataWord.ONE) {
throw new IllegalArgumentException("Can't dispose a global DataWord");
}

// If there are enough cached values, just really dispose
if (dataWordPool.size()<1024) {
if (dataWordPool.size() < 1024) {
dataWordPool.push(dw);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Object[] data() {
TestSystemProperties bambooConfig = new TestSystemProperties() {
@Override
protected BlockchainNetConfig buildBlockchainConfig() {
return RegTestConfig.getFromConfig(new HardForkActivationConfig(Integer.MAX_VALUE));
return RegTestConfig.getFromConfig(new HardForkActivationConfig(Integer.MAX_VALUE, Integer.MAX_VALUE));
}

@Override
Expand All @@ -53,7 +53,8 @@ public String toString() {
TestSystemProperties orchidConfig = new TestSystemProperties() {
@Override
protected BlockchainNetConfig buildBlockchainConfig() {
return RegTestConfig.getFromConfig(new HardForkActivationConfig(0));
// this method ignores the orchid060 activation height configuration
return RegTestConfig.getFromConfig(new HardForkActivationConfig(0, Integer.MAX_VALUE));
}

@Override
Expand Down
Loading

0 comments on commit 0762aef

Please sign in to comment.