Fix state root mismatch when trying to modify public state from priv tx (#118)

Signed-off-by: Ivaylo Kirilov <iikirilov@gmail.com>
Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
pull/125/head
Ivaylo Kirilov 5 years ago committed by Lucas Saldanha
parent 2039674a38
commit b4d0327dce
  1. 97
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java
  2. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractMessageProcessor.java

@ -33,32 +33,34 @@ public class PrivateContractPublicStateAcceptanceTest extends PrivacyAcceptanceT
private static final long POW_CHAIN_ID = 2018;
private PrivacyNode minerNode;
private PrivacyNode transactionNode;
@Before
public void setUp() throws Exception {
minerNode =
privacyBesu.createPrivateTransactionEnabledMinerNode(
"miner-node", privacyAccountResolver.resolve(0));
privacyCluster.start(minerNode);
transactionNode =
privacyBesu.createPrivateTransactionEnabledNode(
"transaction-node", privacyAccountResolver.resolve(1));
privacyCluster.start(minerNode, transactionNode);
}
@Test
public void mustAllowAccessToPublicStateFromPrivateTx() throws Exception {
final EventEmitter publicEventEmitter =
minerNode.getBesu().execute((contractTransactions.createSmartContract(EventEmitter.class)));
transactionNode.execute((contractTransactions.createSmartContract(EventEmitter.class)));
final TransactionReceipt receipt = publicEventEmitter.store(BigInteger.valueOf(12)).send();
assertThat(receipt).isNotNull();
final CrossContractReader reader =
minerNode
.getBesu()
.execute(
privateContractTransactions.createSmartContract(
CrossContractReader.class,
minerNode.getTransactionSigningKey(),
POW_CHAIN_ID,
minerNode.getEnclaveKey()));
transactionNode.execute(
privateContractTransactions.createSmartContract(
CrossContractReader.class,
transactionNode.getTransactionSigningKey(),
POW_CHAIN_ID,
transactionNode.getEnclaveKey()));
assertThat(reader.read(publicEventEmitter.getContractAddress()).send())
.isEqualTo(BigInteger.valueOf(12));
@ -67,22 +69,19 @@ public class PrivateContractPublicStateAcceptanceTest extends PrivacyAcceptanceT
@Test(expected = ContractCallException.class)
public void mustNotAllowAccessToPrivateStateFromPublicTx() throws Exception {
final EventEmitter privateEventEmitter =
minerNode
.getBesu()
.execute(
(privateContractTransactions.createSmartContract(
EventEmitter.class,
minerNode.getTransactionSigningKey(),
POW_CHAIN_ID,
minerNode.getEnclaveKey())));
transactionNode.execute(
(privateContractTransactions.createSmartContract(
EventEmitter.class,
transactionNode.getTransactionSigningKey(),
POW_CHAIN_ID,
transactionNode.getEnclaveKey())));
final TransactionReceipt receipt = privateEventEmitter.store(BigInteger.valueOf(12)).send();
assertThat(receipt).isNotNull();
final CrossContractReader publicReader =
minerNode
.getBesu()
.execute(contractTransactions.createSmartContract(CrossContractReader.class));
transactionNode.execute(
contractTransactions.createSmartContract(CrossContractReader.class));
publicReader.read(privateEventEmitter.getContractAddress()).send();
}
@ -90,19 +89,16 @@ public class PrivateContractPublicStateAcceptanceTest extends PrivacyAcceptanceT
@Test
public void privateContractMustNotBeAbleToCallPublicContractWhichChangesState() throws Exception {
final CrossContractReader privateReader =
minerNode
.getBesu()
.execute(
privateContractTransactions.createSmartContract(
CrossContractReader.class,
minerNode.getTransactionSigningKey(),
POW_CHAIN_ID,
minerNode.getEnclaveKey()));
transactionNode.execute(
privateContractTransactions.createSmartContract(
CrossContractReader.class,
transactionNode.getTransactionSigningKey(),
POW_CHAIN_ID,
transactionNode.getEnclaveKey()));
final CrossContractReader publicReader =
minerNode
.getBesu()
.execute(contractTransactions.createSmartContract(CrossContractReader.class));
transactionNode.execute(
contractTransactions.createSmartContract(CrossContractReader.class));
final PrivateTransactionReceipt transactionReceipt =
(PrivateTransactionReceipt)
@ -115,19 +111,16 @@ public class PrivateContractPublicStateAcceptanceTest extends PrivacyAcceptanceT
public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesContract()
throws Exception {
final CrossContractReader privateReader =
minerNode
.getBesu()
.execute(
privateContractTransactions.createSmartContract(
CrossContractReader.class,
minerNode.getTransactionSigningKey(),
POW_CHAIN_ID,
minerNode.getEnclaveKey()));
transactionNode.execute(
privateContractTransactions.createSmartContract(
CrossContractReader.class,
transactionNode.getTransactionSigningKey(),
POW_CHAIN_ID,
transactionNode.getEnclaveKey()));
final CrossContractReader publicReader =
minerNode
.getBesu()
.execute(contractTransactions.createSmartContract(CrossContractReader.class));
transactionNode.execute(
contractTransactions.createSmartContract(CrossContractReader.class));
final PrivateTransactionReceipt transactionReceipt =
(PrivateTransactionReceipt)
@ -137,19 +130,17 @@ public class PrivateContractPublicStateAcceptanceTest extends PrivacyAcceptanceT
}
@Test
public void privateContractMustNotBeAbleToCallSelfDetructOfPublicContract() throws Exception {
public void privateContractMustNotBeAbleToCallSelfDestructOnPublicContract() throws Exception {
final CrossContractReader privateReader =
minerNode
.getBesu()
.execute(
privateContractTransactions.createSmartContract(
CrossContractReader.class,
minerNode.getTransactionSigningKey(),
POW_CHAIN_ID,
minerNode.getEnclaveKey()));
transactionNode.execute(
privateContractTransactions.createSmartContract(
CrossContractReader.class,
transactionNode.getTransactionSigningKey(),
POW_CHAIN_ID,
transactionNode.getEnclaveKey()));
final CrossContractReader publicReader =
minerNode
transactionNode
.getBesu()
.execute(contractTransactions.createSmartContract(CrossContractReader.class));

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.mainnet;
import org.hyperledger.besu.ethereum.core.Account;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.ModificationNotAllowedException;
import org.hyperledger.besu.ethereum.vm.EVM;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.hyperledger.besu.ethereum.vm.OperationTracer;
@ -155,6 +156,8 @@ public abstract class AbstractMessageProcessor {
evm.runToHalt(frame, operationTracer);
} catch (final ExceptionalHaltException e) {
frame.setState(MessageFrame.State.EXCEPTIONAL_HALT);
} catch (final ModificationNotAllowedException e) {
frame.setState(MessageFrame.State.REVERT);
}
}

Loading…
Cancel
Save