Skip to content

Commit

Permalink
Merge pull request ethereum#1246 from ethereum/constantinople
Browse files Browse the repository at this point in the history
Schedule Constantinople on Mainnet + tests fixed
  • Loading branch information
zilm13 authored Dec 26, 2018
2 parents 602ca25 + 444e8dc commit b7d13a2
Show file tree
Hide file tree
Showing 26 changed files with 353 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public MainNetConfig() {
add(2_463_000, new Eip150HFConfig(new DaoHFConfig()));
add(2_675_000, new Eip160HFConfig(new DaoHFConfig()));
add(4_370_000, new ByzantiumConfig(new DaoHFConfig()));
add(7_080_000, new ConstantinopleConfig(new DaoHFConfig()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,19 +289,24 @@ private void create() {
m_endGas = m_endGas.subtract(BigInteger.valueOf(basicTxCost));
result.spendGas(basicTxCost);
} else {
Repository originalRepo = track;
// Some TCK tests have storage only addresses (no code, zero nonce etc) - impossible situation in the real network
// So, we should clean up it before reuse, but as tx not always goes successful, state should be correctly
// reverted in that case too
if (cacheTrack.hasContractDetails(newContractAddress)) {
originalRepo = track.clone();
originalRepo.delete(newContractAddress);
}
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(tx, currentBlock,
cacheTrack, track, blockStore);
cacheTrack, originalRepo, blockStore);

this.vm = new VM(config, vmHook);
this.program = new Program(tx.getData(), programInvoke, tx, config, vmHook).withCommonConfig(commonConfig);

// reset storage if the contract with the same address already exists
// TCK test case only - normally this is near-impossible situation in the real network
// TODO make via Trie.clear() without keyset
// ContractDetails contractDetails = program.getStorage().getContractDetails(newContractAddress);
// for (DataWord key : contractDetails.getStorageKeys()) {
// program.storageSave(key, DataWord.ZERO);
// }
ContractDetails contractDetails = program.getStorage().getContractDetails(newContractAddress);
contractDetails.deleteStorage();
}

BigInteger endowment = toBI(tx.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public interface ContractDetails {

Set<DataWord> getStorageKeys();

// Removes all storage, key by key, if supported
void deleteStorage();

Map<DataWord,DataWord> getStorage(@Nullable Collection<DataWord> keys);

Map<DataWord, DataWord> getStorage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ public Set<DataWord> getStorageKeys() {
throw new RuntimeException("Not supported");
}

@Override
public void deleteStorage() {
// do nothing as getStorageKeys() is not supported
}

@Override
public Map<DataWord, DataWord> getStorage(@Nullable Collection<DataWord> keys) {
throw new RuntimeException("Not supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public Pair<Boolean, byte[]> execute(byte[] data) {

// check if modulus is zero
if (isZero(mod))
return Pair.of(true, EMPTY_BYTE_ARRAY);
return Pair.of(true, new byte[modLen]); // should keep length of the result

byte[] res = stripLeadingZeroes(base.modPow(exp, mod).toByteArray());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,17 @@ private void createContractImpl(DataWord value, byte[] programCode, byte[] newAd
// [5] COOK THE INVOKE AND EXECUTE
byte[] nonce = getStorage().getNonce(senderAddress).toByteArray();
InternalTransaction internalTx = addInternalTx(nonce, getGasLimit(), senderAddress, null, endowment, programCode, "create");
Repository originalRepo = this.invoke.getOrigRepository();
// Some TCK tests have storage only addresses (no code, zero nonce etc) - impossible situation in the real network
// So, we should clean up it before reuse, but as tx not always goes successful, state should be correctly
// reverted in that case too
if (!contractAlreadyExists && track.hasContractDetails(newAddress)) {
originalRepo = originalRepo.clone();
originalRepo.delete(newAddress);
}
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(
this, DataWord.of(newAddress), getOwnerAddress(), value, gasLimit,
newBalance, null, track, this.invoke.getOrigRepository(), this.invoke.getBlockStore(), false, byTestingSuite());
newBalance, null, track, originalRepo, this.invoke.getBlockStore(), false, byTestingSuite());

ProgramResult result = ProgramResult.createEmpty();

Expand All @@ -532,6 +540,10 @@ private void createContractImpl(DataWord value, byte[] programCode, byte[] newAd
} else if (isNotEmpty(programCode)) {
VM vm = new VM(config, vmHook);
Program program = new Program(programCode, programInvoke, internalTx, config, vmHook).withCommonConfig(commonConfig);
// reset storage if the contract with the same address already exists
// TCK test case only - normally this is near-impossible situation in the real network
ContractDetails contractDetails = program.getStorage().getContractDetails(newAddress);
contractDetails.deleteStorage();
vm.play(program);
result = program.getResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class GitHubBasicTest {

String commitSHA = "95a309203890e6244c6d4353ca411671973c13b5";
String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f";

@Test
public void btCrypto() throws IOException {
Expand All @@ -55,6 +55,11 @@ public void btDifficultyByzantium() throws IOException, ParseException {
runDifficultyTest(new ByzantiumConfig(new DaoHFConfig()), "BasicTests/difficultyByzantium.json", commitSHA);
}

@Test
public void btDifficultyConstantinople() throws IOException, ParseException {
runDifficultyTest(new ConstantinopleConfig(new DaoHFConfig()), "BasicTests/difficultyConstantinople.json", commitSHA);
}

@Test
@Ignore // due to CPP minimumDifficulty issue
public void btDifficultyCustomHomestead() throws IOException, ParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class GitHubBlockStateTest {

static String commitSHA = "7f638829311dfc1d341c1db85d8a891f57fa4da7";
static String treeSHA = "9b96943196bfbb8b49651eab5e479956d7dabcc7"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/GeneralStateTests/
static String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f";
static String treeSHA = "724427f69f5573ed0f504a534b3ecbcd3070fa28"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/GeneralStateTests/

static GitHubJSONTestSuite.Network[] targetNets = {
GitHubJSONTestSuite.Network.Frontier,
GitHubJSONTestSuite.Network.Homestead,
GitHubJSONTestSuite.Network.EIP150,
GitHubJSONTestSuite.Network.EIP158,
GitHubJSONTestSuite.Network.Byzantium
GitHubJSONTestSuite.Network.Byzantium,
GitHubJSONTestSuite.Network.Constantinople
};

static BlockchainTestSuite suite;
Expand Down Expand Up @@ -153,7 +154,6 @@ public void bcStPreCompiledContracts2() throws IOException {
}

@Test
@Ignore
public void bcStMemoryStressTest() throws IOException {
Set<String> excluded = new HashSet<>();
excluded.add("mload32bitBound_return2");// The test extends memory to 4Gb which can't be handled with Java arrays
Expand Down Expand Up @@ -302,42 +302,22 @@ public void stCodeCopyTest() throws IOException {
}

@Test
@Ignore("Broken tests format, delayed until resolved")
public void stExtCodeHashCallCode() throws IOException {
String commit = "10ab37c095bb87d2e781bcf112b6104912fccb44";
String filePath = "GeneralStateTests/stExtCodeHash/extCodeHashCallCode_d0g0v0.json";
BlockchainTestSuite.runSingle(filePath, commit, GitHubJSONTestSuite.Network.Constantinople);
BlockchainTestSuite.runSingle(filePath, commit, GitHubJSONTestSuite.Network.Byzantium);
}

@Test
@Ignore("Broken tests format, delayed until resolved")
public void stExtCodeHashCall() throws IOException {
String commit = "10ab37c095bb87d2e781bcf112b6104912fccb44";
String filePath = "GeneralStateTests/stExtCodeHash/extCodeHashCall_d0g0v0.json";
BlockchainTestSuite.runSingle(filePath, commit, GitHubJSONTestSuite.Network.Constantinople);
BlockchainTestSuite.runSingle(filePath, commit, GitHubJSONTestSuite.Network.Byzantium);
public void stExtCodeHash() throws IOException {
suite.runAll("stExtCodeHash");
}

@Test
@Ignore("Update after all tests could pass latest develop")
public void stShiftTest() throws IOException {
suite.runAll("stShift");
// TODO: Update all, this one passes with following settings:
// String commitSHA = "560e2cd6cf881821180d46d9cc4c542e19cfea1d";
// String treeSHA = "8457a6a49f53218575a349abc311c55939797bff";
// targetNets += GitHubJSONTestSuite.Network.Constantinople
}

@Test
@Ignore("Update after all tests could pass latest develop")
public void stCreate2Test() throws IOException {
suite.runAll("stCreate2", new HashSet<>(Arrays.asList(
"create2collisionStorage_d1g0v0" // Tests excluded because they test unreal prestate
))); // (nonce, balance 0, code empty, but some storage)
// TODO: Update all, this one passes with following settings:
// String commitSHA = "e2d84e1c00289bc259ad631efb6b42390e6a291a";
// String treeSHA = "d74573a79cf607744759acde258bf7c3cf849bf1";
// targetNets += GitHubJSONTestSuite.Network.Constantinople
suite.runAll("stCreate2");
}

@Test
public void stSstoreTest() throws IOException {
suite.runAll("stSStoreTest");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class GitHubBlockTest {

static String commitSHA = "7f638829311dfc1d341c1db85d8a891f57fa4da7";
static String treeSHA = "3f6a1117be5c0d6f801875118c7c580dc4200712"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/
static String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f";
static String treeSHA = "6c32ebcbce50112966427e18788069b9f7cbe285"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/
static GitHubJSONTestSuite.Network[] targetNets = {
GitHubJSONTestSuite.Network.Frontier,
GitHubJSONTestSuite.Network.Homestead,
GitHubJSONTestSuite.Network.EIP150,
GitHubJSONTestSuite.Network.EIP158,
GitHubJSONTestSuite.Network.Byzantium
GitHubJSONTestSuite.Network.Byzantium,
GitHubJSONTestSuite.Network.Constantinople
};

static BlockchainTestSuite suite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ public enum Network {
FrontierToHomesteadAt5,
HomesteadToDaoAt5,
HomesteadToEIP150At5,
EIP158ToByzantiumAt5;
EIP158ToByzantiumAt5,
ByzantiumToConstantinopleAt5;

public BlockchainNetConfig getConfig() {
switch (this) {
Expand Down Expand Up @@ -356,6 +357,11 @@ public BlockchainNetConfig getConfig() {
add(5, new ByzantiumConfig(new HomesteadConfig()));
}};

case ByzantiumToConstantinopleAt5: return new BaseNetConfig() {{
add(0, new ByzantiumConfig(new HomesteadConfig()));
add(5, new ConstantinopleConfig(new HomesteadConfig()));
}};

default: throw new IllegalArgumentException("Unknown network value: " + this.name());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class GitHubPowTest {

private static final Logger logger = LoggerFactory.getLogger("TCK-Test");
public String shacommit = "b09975f0a37afe306f52d5b771f5e3836f53c8bc";
public String shacommit = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f";

@Test
public void runEthashTest() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class GitHubStateTest {

static String commitSHA = "7f638829311dfc1d341c1db85d8a891f57fa4da7";
static String treeSHA = "d1ece13ebfb2adb27061ae5a6155bd9ed9773d8f"; // https://github.com/ethereum/tests/tree/develop/GeneralStateTests/
static String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f";
static String treeSHA = "51fd8f9969ff488917f0832c57ece01f66516db2"; // https://github.com/ethereum/tests/tree/develop/GeneralStateTests/
static GitHubJSONTestSuite.Network[] targetNets = {
GitHubJSONTestSuite.Network.Frontier,
GitHubJSONTestSuite.Network.Homestead,
GitHubJSONTestSuite.Network.EIP150,
GitHubJSONTestSuite.Network.EIP158,
GitHubJSONTestSuite.Network.Byzantium
GitHubJSONTestSuite.Network.Byzantium,
GitHubJSONTestSuite.Network.Constantinople
};

static GeneralStateTestSuite suite;
Expand Down Expand Up @@ -152,7 +153,6 @@ public void stPreCompiledContracts2() throws IOException {
}

@Test
@Ignore
public void stMemoryStressTest() throws IOException {
Set<String> excluded = new HashSet<>();
excluded.add("mload32bitBound_return2");// The test extends memory to 4Gb which can't be handled with Java arrays
Expand All @@ -162,7 +162,6 @@ public void stMemoryStressTest() throws IOException {
}

@Test
@Ignore
public void stMemoryTest() throws IOException {
suite.runAll("stMemoryTest");
}
Expand Down Expand Up @@ -304,65 +303,23 @@ public void stCodeCopyTest() throws IOException {


@Test
@Ignore("Fails on pre-configured commit, update after test is merged in develop of Github tests")
public void stExtCodeHashCallCode() throws IOException {
String commit = "10ab37c095bb87d2e781bcf112b6104912fccb44";
String filePath = "stExtCodeHash/extCodeHashCallCode.json";
GeneralStateTestSuite.runSingle(filePath, commit, GitHubJSONTestSuite.Network.Constantinople);
GeneralStateTestSuite.runSingle(filePath, commit, GitHubJSONTestSuite.Network.Byzantium);
}

@Test
@Ignore("Fails on pre-configured commit, update after test is merged in develop of Github tests")
public void stExtCodeHashCall() throws IOException {
String commit = "10ab37c095bb87d2e781bcf112b6104912fccb44";
String filePath = "stExtCodeHash/extCodeHashCall.json";
GeneralStateTestSuite.runSingle(filePath, commit, GitHubJSONTestSuite.Network.Constantinople);
GeneralStateTestSuite.runSingle(filePath, commit, GitHubJSONTestSuite.Network.Byzantium);
public void stExtCodeHashTest() throws IOException {
suite.runAll("stExtCodeHash");
}

@Test
@Ignore("Update after all tests could pass latest develop")
public void stShiftTest() throws IOException {
suite.runAll("stShift");
// TODO: Update all, this one passes with following settings:
// String commit = "ad2184adca367c0b68c65b44519dba16e1d0b9e2";
// String treeSha = "4dd59a4f448dc06c3641bd5cb9c35cf6a099e438";
// targetNets += GitHubJSONTestSuite.Network.Constantinople
}

@Test
@Ignore("Update after all tests could pass latest develop")
public void stCreate2Test() throws IOException {
suite.runAll("stCreate2", new HashSet<>(Arrays.asList(
"RevertInCreateInInit", // Tests excluded because they test unreal prestate
"create2collisionStorage" // (nonce, balance 0, code empty, but some storage)
)));
// TODO: Update all, this one passes with following settings:
// String commitSHA = "95a309203890e6244c6d4353ca411671973c13b5";
// String treeSHA = "700fdc4aa7d74957a12fbda38785ecc7b846bcc0";
// targetNets += GitHubJSONTestSuite.Network.Constantinople
suite.runAll("stCreate2");
}

@Test
@Ignore("Update after all tests could pass latest develop")
public void stSstoreRefundBug() throws IOException {
final String commit = "9ff64743f0347952903287b9074803607e5855e8";

GeneralStateTestSuite.runSingle("stSStoreTest/SstoreCallToSelfSubRefundBelowZero.json", commit,
GitHubJSONTestSuite.Network.Constantinople);

GeneralStateTestSuite.runSingle("stSStoreTest/sstore_0to0.json", commit,
GitHubJSONTestSuite.Network.Constantinople);

GeneralStateTestSuite.runSingle("stSStoreTest/sstore_Xto0.json", commit,
GitHubJSONTestSuite.Network.Constantinople);

GeneralStateTestSuite.runSingle("stSStoreTest/sstore_XtoX.json", commit,
GitHubJSONTestSuite.Network.Constantinople);

GeneralStateTestSuite.runSingle("stSStoreTest/sstore_XtoY.json", commit,
GitHubJSONTestSuite.Network.Constantinople);
public void stSstoreTest() throws IOException {
suite.runAll("stSStoreTest");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class GitHubTestNetTest {

static String commitSHA = "7f638829311dfc1d341c1db85d8a891f57fa4da7";
static String treeSHA = "12ee51045ace4a3075e39fe58128fdaa74b3fbd0"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/TransitionTests
static String commitSHA = "725dbc73a54649e22a00330bd0f4d6699a5060e5";
static String treeSHA = "36528084e10bf993fdb20cc304f3421c7324c2a4"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/TransitionTests

static BlockchainTestSuite suite;

Expand Down Expand Up @@ -65,4 +65,9 @@ public void bcHomesteadToEIP150() throws IOException {
public void bcEIP158ToByzantium() throws IOException {
suite.runAll("bcEIP158ToByzantium", GitHubJSONTestSuite.Network.EIP158ToByzantiumAt5);
}

@Test
public void byzantiumToConstantinople() throws IOException {
suite.runAll("bcByzantiumToConstantinople", GitHubJSONTestSuite.Network.ByzantiumToConstantinopleAt5);
}
}
Loading

0 comments on commit b7d13a2

Please sign in to comment.