From 0b8407ba296b1ef5a2902533de50e338693109a5 Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Mon, 9 Sep 2019 11:12:28 +0100 Subject: [PATCH 01/10] Adds acceptance test for accessing public state from private transaction --- .../privacy/PrivacyAcceptanceTestBase.java | 3 +- .../tests/web3j/CrossContractReader.sol | 26 +++ .../web3j/generated/CrossContractReader.abi | 1 + .../web3j/generated/CrossContractReader.bin | 1 + .../web3j/generated/CrossContractReader.java | 156 ++++++++++++++++++ ...vateContractPublicStateAcceptanceTest.java | 64 +++++++ 6 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol create mode 100644 acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi create mode 100644 acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin create mode 100644 acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java create mode 100644 acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java index efd1c3a24e..0620d1503c 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java @@ -12,6 +12,7 @@ */ package tech.pegasys.pantheon.tests.acceptance.dsl.privacy; +import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.NetConditions; import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.privacy.PrivacyNodeFactory; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.account.PrivacyAccountResolver; @@ -25,7 +26,7 @@ import org.junit.ClassRule; import org.junit.rules.TemporaryFolder; -public class PrivacyAcceptanceTestBase { +public class PrivacyAcceptanceTestBase extends AcceptanceTestBase { @ClassRule public static final TemporaryFolder privacy = new TemporaryFolder(); protected final PrivacyTransactions privacyTransactions; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol new file mode 100644 index 0000000000..28d2d55fac --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol @@ -0,0 +1,26 @@ +/* + * Copyright 2018 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +pragma solidity >=0.4.0 <0.6.0; + +import "./EventEmitter.sol"; + +// compile with: +// solc CrossContractReader.sol --bin --abi --optimize --overwrite -o . +// then create web3j wrappers with: +// web3j solidity generate -b ./generated/CrossContractReader.bin -a ./generated/CrossContractReader.abi -o ../../../../../ -p tech.pegasys.pantheon.tests.web3j.generated +contract CrossContractReader { + function read(address emitter_address) view public returns (uint) { + EventEmitter em = EventEmitter(emitter_address); + return em.value(); + } +} \ No newline at end of file diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi new file mode 100644 index 0000000000..1c71ebc687 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"emitter_address","type":"address"}],"name":"read","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin new file mode 100644 index 0000000000..50a4322067 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50610106806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063a087a87e14602d575b600080fd5b605060048036036020811015604157600080fd5b50356001600160a01b03166062565b60408051918252519081900360200190f35b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b15801560a057600080fd5b505afa15801560b3573d6000803e3d6000fd5b505050506040513d602081101560c857600080fd5b5051939250505056fea265627a7a723058207f9edd1fef554b145dd0c7153470dca7d8aac411e17dcdeeb2b6ea17b9f394a964736f6c634300050a0032 \ No newline at end of file diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java new file mode 100644 index 0000000000..fcaf4b5b24 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java @@ -0,0 +1,156 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.tests.web3j.generated; + +import java.math.BigInteger; +import java.util.Arrays; + +import org.web3j.abi.TypeReference; +import org.web3j.abi.datatypes.Function; +import org.web3j.abi.datatypes.Type; +import org.web3j.abi.datatypes.generated.Uint256; +import org.web3j.crypto.Credentials; +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.RemoteCall; +import org.web3j.tx.Contract; +import org.web3j.tx.TransactionManager; +import org.web3j.tx.gas.ContractGasProvider; + +/** + * Auto generated code. + * + *

Do not modify! + * + *

Please use the web3j command line tools, + * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the codegen module to update. + * + *

Generated with web3j version 4.2.0. + */ +@SuppressWarnings("rawtypes") +public class CrossContractReader extends Contract { + private static final String BINARY = + "608060405234801561001057600080fd5b50610106806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063a087a87e14602d575b600080fd5b605060048036036020811015604157600080fd5b50356001600160a01b03166062565b60408051918252519081900360200190f35b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b15801560a057600080fd5b505afa15801560b3573d6000803e3d6000fd5b505050506040513d602081101560c857600080fd5b5051939250505056fea265627a7a723058207f9edd1fef554b145dd0c7153470dca7d8aac411e17dcdeeb2b6ea17b9f394a964736f6c634300050a0032"; + + public static final String FUNC_READ = "read"; + + @Deprecated + protected CrossContractReader( + String contractAddress, + Web3j web3j, + Credentials credentials, + BigInteger gasPrice, + BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + protected CrossContractReader( + String contractAddress, + Web3j web3j, + Credentials credentials, + ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, credentials, contractGasProvider); + } + + @Deprecated + protected CrossContractReader( + String contractAddress, + Web3j web3j, + TransactionManager transactionManager, + BigInteger gasPrice, + BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + protected CrossContractReader( + String contractAddress, + Web3j web3j, + TransactionManager transactionManager, + ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); + } + + public RemoteCall read(String emitter_address) { + final Function function = + new Function( + FUNC_READ, + Arrays.asList(new org.web3j.abi.datatypes.Address(emitter_address)), + Arrays.>asList(new TypeReference() {})); + return executeRemoteCallSingleValueReturn(function, BigInteger.class); + } + + @Deprecated + public static CrossContractReader load( + String contractAddress, + Web3j web3j, + Credentials credentials, + BigInteger gasPrice, + BigInteger gasLimit) { + return new CrossContractReader(contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + @Deprecated + public static CrossContractReader load( + String contractAddress, + Web3j web3j, + TransactionManager transactionManager, + BigInteger gasPrice, + BigInteger gasLimit) { + return new CrossContractReader(contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + public static CrossContractReader load( + String contractAddress, + Web3j web3j, + Credentials credentials, + ContractGasProvider contractGasProvider) { + return new CrossContractReader(contractAddress, web3j, credentials, contractGasProvider); + } + + public static CrossContractReader load( + String contractAddress, + Web3j web3j, + TransactionManager transactionManager, + ContractGasProvider contractGasProvider) { + return new CrossContractReader(contractAddress, web3j, transactionManager, contractGasProvider); + } + + public static RemoteCall deploy( + Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { + return deployRemoteCall( + CrossContractReader.class, web3j, credentials, contractGasProvider, BINARY, ""); + } + + @Deprecated + public static RemoteCall deploy( + Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + return deployRemoteCall( + CrossContractReader.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); + } + + public static RemoteCall deploy( + Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return deployRemoteCall( + CrossContractReader.class, web3j, transactionManager, contractGasProvider, BINARY, ""); + } + + @Deprecated + public static RemoteCall deploy( + Web3j web3j, + TransactionManager transactionManager, + BigInteger gasPrice, + BigInteger gasLimit) { + return deployRemoteCall( + CrossContractReader.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java new file mode 100644 index 0000000000..391bd7b823 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.tests.web3j.privacy; + +import static org.junit.Assert.assertNotNull; + +import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase; +import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; +import tech.pegasys.pantheon.tests.web3j.generated.CrossContractReader; +import tech.pegasys.pantheon.tests.web3j.generated.EventEmitter; + +import java.math.BigInteger; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.web3j.protocol.core.methods.response.TransactionReceipt; + +public class PrivateContractPublicStateAcceptanceTest extends PrivacyAcceptanceTestBase { + private static final long POW_CHAIN_ID = 2018; + + private PrivacyNode minerNode; + + @Before + public void setUp() throws Exception { + minerNode = + privacyPantheon.createPrivateTransactionEnabledMinerNode( + "miner-node", privacyAccountResolver.resolve(0)); + privacyCluster.start(minerNode); + } + + @Test + public void mustAllowAccessToPublicStateFromPrivateTx() throws Exception { + final EventEmitter publicEventEmitter = + minerNode + .getPantheon() + .execute((contractTransactions.createSmartContract(EventEmitter.class))); + + final TransactionReceipt receipt = publicEventEmitter.store(BigInteger.valueOf(12)).send(); + assertNotNull(receipt); + + CrossContractReader reader = + minerNode + .getPantheon() + .execute( + privateContractTransactions.createSmartContract( + CrossContractReader.class, + minerNode.getTransactionSigningKey(), + POW_CHAIN_ID, + minerNode.getEnclaveKey())); + Assert.assertEquals( + reader.read(publicEventEmitter.getContractAddress()).send(), BigInteger.valueOf(12)); + } +} From 8b73f899ed02476791cd8d0ec34bbea9eecdb8e6 Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Mon, 9 Sep 2019 16:52:05 +0100 Subject: [PATCH 02/10] Public state is now accessible from private contracts --- .../privacy/PrivacyAcceptanceTestBase.java | 8 +- ...vateContractPublicStateAcceptanceTest.java | 6 +- .../ethereum/core/ReadOnlyMutableAccount.java | 115 ++++++++++++++++++ .../privacy/PrivacyPrecompiledContract.java | 1 + .../privacy/PrivateTransactionProcessor.java | 9 +- ...efaultMutablePrivateWorldStateUpdater.java | 96 +++++++++++++++ 6 files changed, 225 insertions(+), 10 deletions(-) create mode 100644 ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java create mode 100644 ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java index 0620d1503c..e66f2ccf0f 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java @@ -13,14 +13,12 @@ package tech.pegasys.pantheon.tests.acceptance.dsl.privacy; import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; -import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.NetConditions; import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.privacy.PrivacyNodeFactory; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.account.PrivacyAccountResolver; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.condition.PrivateContractVerifier; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.condition.PrivateTransactionVerifier; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.contract.PrivateContractTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.transaction.PrivacyTransactions; -import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetTransactions; import org.junit.After; import org.junit.ClassRule; @@ -37,10 +35,8 @@ public class PrivacyAcceptanceTestBase extends AcceptanceTestBase { protected final PrivacyCluster privacyCluster; protected final PrivacyAccountResolver privacyAccountResolver; - protected final NetConditions net; - public PrivacyAcceptanceTestBase() { - net = new NetConditions(new NetTransactions()); + super(); privacyTransactions = new PrivacyTransactions(); privateContractVerifier = new PrivateContractVerifier(); privateTransactionVerifier = new PrivateTransactionVerifier(privacyTransactions); @@ -50,8 +46,10 @@ public PrivacyAcceptanceTestBase() { privacyAccountResolver = new PrivacyAccountResolver(); } + @Override @After public void tearDownAcceptanceTestBase() { + cluster.close(); privacyCluster.close(); } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java index 391bd7b823..58c565bcd6 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java @@ -14,6 +14,7 @@ import static org.junit.Assert.assertNotNull; +import org.junit.Assert; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; import tech.pegasys.pantheon.tests.web3j.generated.CrossContractReader; @@ -21,7 +22,6 @@ import java.math.BigInteger; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.web3j.protocol.core.methods.response.TransactionReceipt; @@ -58,7 +58,7 @@ public void mustAllowAccessToPublicStateFromPrivateTx() throws Exception { minerNode.getTransactionSigningKey(), POW_CHAIN_ID, minerNode.getEnclaveKey())); - Assert.assertEquals( - reader.read(publicEventEmitter.getContractAddress()).send(), BigInteger.valueOf(12)); + Assert.assertEquals( + reader.read(publicEventEmitter.getContractAddress()).send(), BigInteger.valueOf(12)); } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java new file mode 100644 index 0000000000..7cd9342625 --- /dev/null +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java @@ -0,0 +1,115 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.ethereum.core; + +import tech.pegasys.pantheon.util.bytes.Bytes32; +import tech.pegasys.pantheon.util.bytes.BytesValue; +import tech.pegasys.pantheon.util.uint.UInt256; + +import java.util.Map; +import java.util.NavigableMap; + +public class ReadOnlyMutableAccount implements MutableAccount { + + private MutableAccount mutableAccount; + + public ReadOnlyMutableAccount(final MutableAccount mutableAccount) { + this.mutableAccount = mutableAccount; + } + + @Override + public void setNonce(final long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setBalance(final Wei value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setCode(final BytesValue code) { + throw new UnsupportedOperationException(); + } + + @Override + public void setVersion(final int version) { + throw new UnsupportedOperationException(); + } + + @Override + public void setStorageValue(final UInt256 key, final UInt256 value) { + throw new UnsupportedOperationException(); + } + + @Override + public void clearStorage() { + throw new UnsupportedOperationException(); + } + + @Override + public Map getUpdatedStorage() { + return mutableAccount.getUpdatedStorage(); + } + + @Override + public Address getAddress() { + return mutableAccount.getAddress(); + } + + @Override + public Hash getAddressHash() { + return mutableAccount.getAddressHash(); + } + + @Override + public long getNonce() { + return mutableAccount.getNonce(); + } + + @Override + public Wei getBalance() { + return mutableAccount.getBalance(); + } + + @Override + public BytesValue getCode() { + return mutableAccount.getCode(); + } + + @Override + public Hash getCodeHash() { + return mutableAccount.getCodeHash(); + } + + @Override + public int getVersion() { + return mutableAccount.getVersion(); + } + + @Override + public UInt256 getStorageValue(final UInt256 key) { + return mutableAccount.getStorageValue(key); + } + + @Override + public UInt256 getOriginalStorageValue(final UInt256 key) { + return mutableAccount.getOriginalStorageValue(key); + } + + @Override + public NavigableMap storageEntriesFrom( + final Bytes32 startKeyHash, final int limit) { + throw new UnsupportedOperationException(); + } +} diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java index 6982437884..72b614346e 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java @@ -120,6 +120,7 @@ public BytesValue compute(final BytesValue input, final MessageFrame messageFram privateWorldStateArchive.getMutable(lastRootHash).get(); final WorldUpdater privateWorldStateUpdater = disposablePrivateState.updater(); + final PrivateTransactionProcessor.Result result = privateTransactionProcessor.processTransaction( messageFrame.getBlockchain(), diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionProcessor.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionProcessor.java index 7ca1a1dc8a..9f645c9153 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionProcessor.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionProcessor.java @@ -32,6 +32,7 @@ import tech.pegasys.pantheon.ethereum.vm.GasCalculator; import tech.pegasys.pantheon.ethereum.vm.MessageFrame; import tech.pegasys.pantheon.ethereum.vm.OperationTracer; +import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutablePrivateWorldStateUpdater; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.util.ArrayDeque; @@ -210,6 +211,10 @@ public Result processTransaction( final MessageFrame initialFrame; final Deque messageFrameStack = new ArrayDeque<>(); + + final WorldUpdater mungedUpUpdater = + new DefaultMutablePrivateWorldStateUpdater(publicWorldState, privateWorldState.updater()); + if (transaction.isContractCreation()) { final Address privateContractAddress = Address.privateContractAddress(senderAddress, previousNonce, privacyGroupId); @@ -226,7 +231,7 @@ public Result processTransaction( .type(MessageFrame.Type.CONTRACT_CREATION) .messageFrameStack(messageFrameStack) .blockchain(blockchain) - .worldState(privateWorldState.updater()) + .worldState(mungedUpUpdater) .address(privateContractAddress) .originator(senderAddress) .contract(privateContractAddress) @@ -255,7 +260,7 @@ public Result processTransaction( .type(MessageFrame.Type.MESSAGE_CALL) .messageFrameStack(messageFrameStack) .blockchain(blockchain) - .worldState(privateWorldState.updater()) + .worldState(mungedUpUpdater) .address(to) .originator(senderAddress) .contract(to) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java new file mode 100644 index 0000000000..3c98fe8311 --- /dev/null +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java @@ -0,0 +1,96 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.ethereum.worldstate; + +import tech.pegasys.pantheon.ethereum.core.Account; +import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.ethereum.core.MutableAccount; +import tech.pegasys.pantheon.ethereum.core.ReadOnlyMutableAccount; +import tech.pegasys.pantheon.ethereum.core.Wei; +import tech.pegasys.pantheon.ethereum.core.WorldUpdater; + +import java.util.Collection; + +public class DefaultMutablePrivateWorldStateUpdater implements WorldUpdater { + + private final WorldUpdater publicWorldUpdater; + private final WorldUpdater privateWorldUpdater; + + public DefaultMutablePrivateWorldStateUpdater( + final WorldUpdater publicWorldUpdater, final WorldUpdater privateWorldUpdater) { + this.publicWorldUpdater = publicWorldUpdater; + this.privateWorldUpdater = privateWorldUpdater; + } + + @Override + public MutableAccount createAccount(final Address address, final long nonce, final Wei balance) { + return privateWorldUpdater.createAccount(address); + } + + @Override + public MutableAccount createAccount(final Address address) { + return privateWorldUpdater.createAccount(address); + } + + @Override + public MutableAccount getOrCreate(final Address address) { + return privateWorldUpdater.getOrCreate(address); + } + + @Override + public MutableAccount getMutable(final Address address) { + final MutableAccount privateAccount = privateWorldUpdater.getMutable(address); + if (privateAccount!= null && !privateAccount.isEmpty()) { + return privateAccount; + } + final MutableAccount publicAccount = publicWorldUpdater.getMutable(address); + if (publicAccount != null && !publicAccount.isEmpty()) { + return new ReadOnlyMutableAccount(publicAccount); + } + return null; + } + + @Override + public void deleteAccount(final Address address) { + privateWorldUpdater.deleteAccount(address); + } + + @Override + public Collection getTouchedAccounts() { + return privateWorldUpdater.getTouchedAccounts(); + } + + @Override + public void revert() { + privateWorldUpdater.revert(); + } + + @Override + public void commit() { + privateWorldUpdater.commit(); + } + + @Override + public Account get(final Address address) { + final Account privateAccount = privateWorldUpdater.get(address); + if (privateAccount != null && !privateAccount.isEmpty()) { + return privateAccount; + } + return publicWorldUpdater.get(address); + } + + @Override + public WorldUpdater updater() { + return this; + } +} From a1365253a9d5121193403a7410889e37f3714a79 Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Mon, 9 Sep 2019 21:21:15 +0100 Subject: [PATCH 03/10] Spotless --- .../privacy/PrivateContractPublicStateAcceptanceTest.java | 6 +++--- .../worldstate/DefaultMutablePrivateWorldStateUpdater.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java index 58c565bcd6..391bd7b823 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java @@ -14,7 +14,6 @@ import static org.junit.Assert.assertNotNull; -import org.junit.Assert; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; import tech.pegasys.pantheon.tests.web3j.generated.CrossContractReader; @@ -22,6 +21,7 @@ import java.math.BigInteger; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.web3j.protocol.core.methods.response.TransactionReceipt; @@ -58,7 +58,7 @@ public void mustAllowAccessToPublicStateFromPrivateTx() throws Exception { minerNode.getTransactionSigningKey(), POW_CHAIN_ID, minerNode.getEnclaveKey())); - Assert.assertEquals( - reader.read(publicEventEmitter.getContractAddress()).send(), BigInteger.valueOf(12)); + Assert.assertEquals( + reader.read(publicEventEmitter.getContractAddress()).send(), BigInteger.valueOf(12)); } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java index 3c98fe8311..037018c871 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java @@ -50,7 +50,7 @@ public MutableAccount getOrCreate(final Address address) { @Override public MutableAccount getMutable(final Address address) { final MutableAccount privateAccount = privateWorldUpdater.getMutable(address); - if (privateAccount!= null && !privateAccount.isEmpty()) { + if (privateAccount != null && !privateAccount.isEmpty()) { return privateAccount; } final MutableAccount publicAccount = publicWorldUpdater.getMutable(address); From 65288eea04a4dfef529947156b285690fa389993 Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Tue, 10 Sep 2019 22:33:23 +0100 Subject: [PATCH 04/10] Adds some more tests, but still need to figure out why no exception on create public contract from private contract --- .../tests/web3j/CrossContractReader.sol | 17 +- .../web3j/generated/CrossContractReader.abi | 2 +- .../web3j/generated/CrossContractReader.bin | 2 +- .../web3j/generated/CrossContractReader.java | 270 +++++++++--------- ...vateContractPublicStateAcceptanceTest.java | 57 +++- .../ethereum/core/ReadOnlyMutableAccount.java | 181 ++++++------ ...efaultMutablePrivateWorldStateUpdater.java | 3 +- 7 files changed, 298 insertions(+), 234 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol index 28d2d55fac..e13abee5bb 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol @@ -19,8 +19,23 @@ import "./EventEmitter.sol"; // then create web3j wrappers with: // web3j solidity generate -b ./generated/CrossContractReader.bin -a ./generated/CrossContractReader.abi -o ../../../../../ -p tech.pegasys.pantheon.tests.web3j.generated contract CrossContractReader { + + event NewEventEmitter( + address contractAddress + ); + function read(address emitter_address) view public returns (uint) { EventEmitter em = EventEmitter(emitter_address); return em.value(); } -} \ No newline at end of file + + function deploy() public { + EventEmitter em = new EventEmitter(); + emit NewEventEmitter(address(em)); + } + + function deployRemote(address crossAddress) public { + CrossContractReader cross = CrossContractReader(crossAddress); + cross.deploy(); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi index 1c71ebc687..d58db9a1a9 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi @@ -1 +1 @@ -[{"constant":true,"inputs":[{"name":"emitter_address","type":"address"}],"name":"read","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] \ No newline at end of file +[{"constant":false,"inputs":[{"name":"crossAddress","type":"address"}],"name":"deployRemote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"deploy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"emitter_address","type":"address"}],"name":"read","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"contractAddress","type":"address"}],"name":"NewEventEmitter","type":"event"}] \ No newline at end of file diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin index 50a4322067..4e023f660c 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b50610106806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063a087a87e14602d575b600080fd5b605060048036036020811015604157600080fd5b50356001600160a01b03166062565b60408051918252519081900360200190f35b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b15801560a057600080fd5b505afa15801560b3573d6000803e3d6000fd5b505050506040513d602081101560c857600080fd5b5051939250505056fea265627a7a723058207f9edd1fef554b145dd0c7153470dca7d8aac411e17dcdeeb2b6ea17b9f394a964736f6c634300050a0032 \ No newline at end of file +608060405234801561001057600080fd5b50610391806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80635374ded214610046578063775c300c1461006e578063a087a87e14610076575b600080fd5b61006c6004803603602081101561005c57600080fd5b50356001600160a01b03166100ae565b005b61006c61010a565b61009c6004803603602081101561008c57600080fd5b50356001600160a01b0316610178565b60408051918252519081900360200190f35b6000819050806001600160a01b031663775c300c6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156100ee57600080fd5b505af1158015610102573d6000803e3d6000fd5b505050505050565b6000604051610118906101ea565b604051809103906000f080158015610134573d6000803e3d6000fd5b50604080516001600160a01b038316815290519192507f9ac6876e0aa40667ffeaa9b359b5ed924f4cdd0e029eb6e9c369e78c68f711fb919081900360200190a150565b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b1580156101b757600080fd5b505afa1580156101cb573d6000803e3d6000fd5b505050506040513d60208110156101e157600080fd5b50519392505050565b610165806101f88339019056fe608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610133806100326000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fa4f2451460415780636057361d14605957806367e404ce146075575b600080fd5b60476097565b60408051918252519081900360200190f35b607360048036036020811015606d57600080fd5b5035609d565b005b607b60ef565b604080516001600160a01b039092168252519081900360200190f35b60025490565b604080513381526020810183905281517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb12b753f3d1aaa2d8f9f5929181900390910190a1600255600180546001600160a01b03191633179055565b6001546001600160a01b03169056fea265627a7a72305820964d6b1168cda84ea2a5bea18eef49bd496a1ff53f7be8178e00cca5dbec045764736f6c634300050a0032a265627a7a723058206bdfc638d14f0f26a6507f178968016fb2a0330e74accb27be8d6e302989fc3264736f6c634300050a0032 \ No newline at end of file diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java index fcaf4b5b24..49bd7a9fc6 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java @@ -1,156 +1,160 @@ -/* - * Copyright 2019 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ package tech.pegasys.pantheon.tests.web3j.generated; +import io.reactivex.Flowable; import java.math.BigInteger; +import java.util.ArrayList; import java.util.Arrays; - +import java.util.Collections; +import java.util.List; +import org.web3j.abi.EventEncoder; import org.web3j.abi.TypeReference; +import org.web3j.abi.datatypes.Address; +import org.web3j.abi.datatypes.Event; import org.web3j.abi.datatypes.Function; import org.web3j.abi.datatypes.Type; import org.web3j.abi.datatypes.generated.Uint256; import org.web3j.crypto.Credentials; import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.DefaultBlockParameter; import org.web3j.protocol.core.RemoteCall; +import org.web3j.protocol.core.methods.request.EthFilter; +import org.web3j.protocol.core.methods.response.Log; +import org.web3j.protocol.core.methods.response.TransactionReceipt; import org.web3j.tx.Contract; import org.web3j.tx.TransactionManager; import org.web3j.tx.gas.ContractGasProvider; /** - * Auto generated code. - * + *

Auto generated code. *

Do not modify! - * *

Please use the web3j command line tools, - * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the codegen module to update. + * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the + * codegen module to update. * *

Generated with web3j version 4.2.0. */ -@SuppressWarnings("rawtypes") public class CrossContractReader extends Contract { - private static final String BINARY = - "608060405234801561001057600080fd5b50610106806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063a087a87e14602d575b600080fd5b605060048036036020811015604157600080fd5b50356001600160a01b03166062565b60408051918252519081900360200190f35b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b15801560a057600080fd5b505afa15801560b3573d6000803e3d6000fd5b505050506040513d602081101560c857600080fd5b5051939250505056fea265627a7a723058207f9edd1fef554b145dd0c7153470dca7d8aac411e17dcdeeb2b6ea17b9f394a964736f6c634300050a0032"; - - public static final String FUNC_READ = "read"; - - @Deprecated - protected CrossContractReader( - String contractAddress, - Web3j web3j, - Credentials credentials, - BigInteger gasPrice, - BigInteger gasLimit) { - super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); - } - - protected CrossContractReader( - String contractAddress, - Web3j web3j, - Credentials credentials, - ContractGasProvider contractGasProvider) { - super(BINARY, contractAddress, web3j, credentials, contractGasProvider); - } - - @Deprecated - protected CrossContractReader( - String contractAddress, - Web3j web3j, - TransactionManager transactionManager, - BigInteger gasPrice, - BigInteger gasLimit) { - super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); - } - - protected CrossContractReader( - String contractAddress, - Web3j web3j, - TransactionManager transactionManager, - ContractGasProvider contractGasProvider) { - super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); - } - - public RemoteCall read(String emitter_address) { - final Function function = - new Function( - FUNC_READ, - Arrays.asList(new org.web3j.abi.datatypes.Address(emitter_address)), - Arrays.>asList(new TypeReference() {})); - return executeRemoteCallSingleValueReturn(function, BigInteger.class); - } - - @Deprecated - public static CrossContractReader load( - String contractAddress, - Web3j web3j, - Credentials credentials, - BigInteger gasPrice, - BigInteger gasLimit) { - return new CrossContractReader(contractAddress, web3j, credentials, gasPrice, gasLimit); - } - - @Deprecated - public static CrossContractReader load( - String contractAddress, - Web3j web3j, - TransactionManager transactionManager, - BigInteger gasPrice, - BigInteger gasLimit) { - return new CrossContractReader(contractAddress, web3j, transactionManager, gasPrice, gasLimit); - } - - public static CrossContractReader load( - String contractAddress, - Web3j web3j, - Credentials credentials, - ContractGasProvider contractGasProvider) { - return new CrossContractReader(contractAddress, web3j, credentials, contractGasProvider); - } - - public static CrossContractReader load( - String contractAddress, - Web3j web3j, - TransactionManager transactionManager, - ContractGasProvider contractGasProvider) { - return new CrossContractReader(contractAddress, web3j, transactionManager, contractGasProvider); - } - - public static RemoteCall deploy( - Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { - return deployRemoteCall( - CrossContractReader.class, web3j, credentials, contractGasProvider, BINARY, ""); - } - - @Deprecated - public static RemoteCall deploy( - Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { - return deployRemoteCall( - CrossContractReader.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); - } - - public static RemoteCall deploy( - Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { - return deployRemoteCall( - CrossContractReader.class, web3j, transactionManager, contractGasProvider, BINARY, ""); - } - - @Deprecated - public static RemoteCall deploy( - Web3j web3j, - TransactionManager transactionManager, - BigInteger gasPrice, - BigInteger gasLimit) { - return deployRemoteCall( - CrossContractReader.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); - } + private static final String BINARY = "608060405234801561001057600080fd5b50610391806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80635374ded214610046578063775c300c1461006e578063a087a87e14610076575b600080fd5b61006c6004803603602081101561005c57600080fd5b50356001600160a01b03166100ae565b005b61006c61010a565b61009c6004803603602081101561008c57600080fd5b50356001600160a01b0316610178565b60408051918252519081900360200190f35b6000819050806001600160a01b031663775c300c6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156100ee57600080fd5b505af1158015610102573d6000803e3d6000fd5b505050505050565b6000604051610118906101ea565b604051809103906000f080158015610134573d6000803e3d6000fd5b50604080516001600160a01b038316815290519192507f9ac6876e0aa40667ffeaa9b359b5ed924f4cdd0e029eb6e9c369e78c68f711fb919081900360200190a150565b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b1580156101b757600080fd5b505afa1580156101cb573d6000803e3d6000fd5b505050506040513d60208110156101e157600080fd5b50519392505050565b610165806101f88339019056fe608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610133806100326000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fa4f2451460415780636057361d14605957806367e404ce146075575b600080fd5b60476097565b60408051918252519081900360200190f35b607360048036036020811015606d57600080fd5b5035609d565b005b607b60ef565b604080516001600160a01b039092168252519081900360200190f35b60025490565b604080513381526020810183905281517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb12b753f3d1aaa2d8f9f5929181900390910190a1600255600180546001600160a01b03191633179055565b6001546001600160a01b03169056fea265627a7a72305820964d6b1168cda84ea2a5bea18eef49bd496a1ff53f7be8178e00cca5dbec045764736f6c634300050a0032a265627a7a723058206bdfc638d14f0f26a6507f178968016fb2a0330e74accb27be8d6e302989fc3264736f6c634300050a0032"; + + public static final String FUNC_DEPLOYREMOTE = "deployRemote"; + + public static final String FUNC_READ = "read"; + + public static final Event NEWEVENTEMITTER_EVENT = new Event("NewEventEmitter", + Arrays.>asList(new TypeReference

() {})); + ; + + @Deprecated + protected CrossContractReader(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + protected CrossContractReader(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, credentials, contractGasProvider); + } + + @Deprecated + protected CrossContractReader(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + protected CrossContractReader(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); + } + + public RemoteCall deployRemote(String crossAddress) { + final Function function = new Function( + FUNC_DEPLOYREMOTE, + Arrays.asList(new org.web3j.abi.datatypes.Address(crossAddress)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteCall deploy() { + final Function function = new Function( + FUNC_DEPLOY, + Arrays.asList(), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteCall read(String emitter_address) { + final Function function = new Function(FUNC_READ, + Arrays.asList(new org.web3j.abi.datatypes.Address(emitter_address)), + Arrays.>asList(new TypeReference() {})); + return executeRemoteCallSingleValueReturn(function, BigInteger.class); + } + + public List getNewEventEmitterEvents(TransactionReceipt transactionReceipt) { + List valueList = extractEventParametersWithLog(NEWEVENTEMITTER_EVENT, transactionReceipt); + ArrayList responses = new ArrayList(valueList.size()); + for (Contract.EventValuesWithLog eventValues : valueList) { + NewEventEmitterEventResponse typedResponse = new NewEventEmitterEventResponse(); + typedResponse.log = eventValues.getLog(); + typedResponse.contractAddress = (String) eventValues.getNonIndexedValues().get(0).getValue(); + responses.add(typedResponse); + } + return responses; + } + + public Flowable newEventEmitterEventFlowable(EthFilter filter) { + return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function() { + @Override + public NewEventEmitterEventResponse apply(Log log) { + Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(NEWEVENTEMITTER_EVENT, log); + NewEventEmitterEventResponse typedResponse = new NewEventEmitterEventResponse(); + typedResponse.log = log; + typedResponse.contractAddress = (String) eventValues.getNonIndexedValues().get(0).getValue(); + return typedResponse; + } + }); + } + + public Flowable newEventEmitterEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { + EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress()); + filter.addSingleTopic(EventEncoder.encode(NEWEVENTEMITTER_EVENT)); + return newEventEmitterEventFlowable(filter); + } + + @Deprecated + public static CrossContractReader load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + return new CrossContractReader(contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + @Deprecated + public static CrossContractReader load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + return new CrossContractReader(contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + public static CrossContractReader load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { + return new CrossContractReader(contractAddress, web3j, credentials, contractGasProvider); + } + + public static CrossContractReader load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return new CrossContractReader(contractAddress, web3j, transactionManager, contractGasProvider); + } + + public static RemoteCall deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { + return deployRemoteCall(CrossContractReader.class, web3j, credentials, contractGasProvider, BINARY, ""); + } + + @Deprecated + public static RemoteCall deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + return deployRemoteCall(CrossContractReader.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); + } + + public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return deployRemoteCall(CrossContractReader.class, web3j, transactionManager, contractGasProvider, BINARY, ""); + } + + @Deprecated + public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + return deployRemoteCall(CrossContractReader.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); + } + + public static class NewEventEmitterEventResponse { + public Log log; + + public String contractAddress; + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java index 391bd7b823..e2a06baf8f 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java @@ -12,8 +12,13 @@ */ package tech.pegasys.pantheon.tests.web3j.privacy; -import static org.junit.Assert.assertNotNull; - +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.web3j.protocol.core.methods.response.TransactionReceipt; +import org.web3j.protocol.eea.response.PrivateTransactionReceipt; +import org.web3j.tx.exceptions.ContractCallException; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; import tech.pegasys.pantheon.tests.web3j.generated.CrossContractReader; @@ -21,10 +26,7 @@ import java.math.BigInteger; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.web3j.protocol.core.methods.response.TransactionReceipt; +import static org.junit.Assert.assertNotNull; public class PrivateContractPublicStateAcceptanceTest extends PrivacyAcceptanceTestBase { private static final long POW_CHAIN_ID = 2018; @@ -61,4 +63,47 @@ public void mustAllowAccessToPublicStateFromPrivateTx() throws Exception { Assert.assertEquals( reader.read(publicEventEmitter.getContractAddress()).send(), BigInteger.valueOf(12)); } + + @Test(expected = ContractCallException.class) + public void mustNotAllowAccessToPrivateStateFromPublicTx() throws Exception { + final EventEmitter privateEventEmitter = + minerNode + .getPantheon() + .execute( + (privateContractTransactions.createSmartContract( + EventEmitter.class, + minerNode.getTransactionSigningKey(), + POW_CHAIN_ID, + minerNode.getEnclaveKey()))); + + final TransactionReceipt receipt = privateEventEmitter.store(BigInteger.valueOf(12)).send(); + assertNotNull(receipt); + + CrossContractReader publicReader = + minerNode + .getPantheon() + .execute(contractTransactions.createSmartContract(CrossContractReader.class)); + + publicReader.read(privateEventEmitter.getContractAddress()).send(); + } + + @Test + public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesContract() throws Exception { + CrossContractReader privateReader = + minerNode + .getPantheon() + .execute( + privateContractTransactions.createSmartContract( + CrossContractReader.class, + minerNode.getTransactionSigningKey(), + POW_CHAIN_ID, + minerNode.getEnclaveKey())); + + CrossContractReader publicReader = minerNode.getPantheon().execute(contractTransactions.createSmartContract(CrossContractReader.class)); + + var transactionReceipt = (PrivateTransactionReceipt) privateReader.deployRemote(publicReader.getContractAddress()).send(); + + + //todo: result here is null which implies tx did not go through, but no error is encountered. + } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java index 7cd9342625..84308083a8 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java @@ -12,6 +12,7 @@ */ package tech.pegasys.pantheon.ethereum.core; +import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutablePrivateWorldStateUpdater; import tech.pegasys.pantheon.util.bytes.Bytes32; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.uint.UInt256; @@ -21,95 +22,93 @@ public class ReadOnlyMutableAccount implements MutableAccount { - private MutableAccount mutableAccount; - - public ReadOnlyMutableAccount(final MutableAccount mutableAccount) { - this.mutableAccount = mutableAccount; - } - - @Override - public void setNonce(final long value) { - throw new UnsupportedOperationException(); - } - - @Override - public void setBalance(final Wei value) { - throw new UnsupportedOperationException(); - } - - @Override - public void setCode(final BytesValue code) { - throw new UnsupportedOperationException(); - } - - @Override - public void setVersion(final int version) { - throw new UnsupportedOperationException(); - } - - @Override - public void setStorageValue(final UInt256 key, final UInt256 value) { - throw new UnsupportedOperationException(); - } - - @Override - public void clearStorage() { - throw new UnsupportedOperationException(); - } - - @Override - public Map getUpdatedStorage() { - return mutableAccount.getUpdatedStorage(); - } - - @Override - public Address getAddress() { - return mutableAccount.getAddress(); - } - - @Override - public Hash getAddressHash() { - return mutableAccount.getAddressHash(); - } - - @Override - public long getNonce() { - return mutableAccount.getNonce(); - } - - @Override - public Wei getBalance() { - return mutableAccount.getBalance(); - } - - @Override - public BytesValue getCode() { - return mutableAccount.getCode(); - } - - @Override - public Hash getCodeHash() { - return mutableAccount.getCodeHash(); - } - - @Override - public int getVersion() { - return mutableAccount.getVersion(); - } - - @Override - public UInt256 getStorageValue(final UInt256 key) { - return mutableAccount.getStorageValue(key); - } - - @Override - public UInt256 getOriginalStorageValue(final UInt256 key) { - return mutableAccount.getOriginalStorageValue(key); - } - - @Override - public NavigableMap storageEntriesFrom( - final Bytes32 startKeyHash, final int limit) { - throw new UnsupportedOperationException(); - } + private MutableAccount mutableAccount; + private final WorldUpdater publicWorldUpdater; + private final WorldUpdater privateWorldUpdater; + + public ReadOnlyMutableAccount(MutableAccount publicAccount, WorldUpdater publicWorldUpdater, WorldUpdater privateWorldUpdater) { + this.mutableAccount = publicAccount; + this.publicWorldUpdater = publicWorldUpdater; + this.privateWorldUpdater = privateWorldUpdater; + } + + @Override + public void setNonce(final long value) { + } + + @Override + public void setBalance(final Wei value) { + } + + @Override + public void setCode(final BytesValue code) { + } + + @Override + public void setVersion(final int version) { + } + + @Override + public void setStorageValue(final UInt256 key, final UInt256 value) { + } + + @Override + public void clearStorage() { + } + + @Override + public Map getUpdatedStorage() { + return mutableAccount.getUpdatedStorage(); + } + + @Override + public Address getAddress() { + return mutableAccount.getAddress(); + } + + @Override + public Hash getAddressHash() { + return mutableAccount.getAddressHash(); + } + + @Override + public long getNonce() { + return mutableAccount.getNonce(); + } + + @Override + public Wei getBalance() { + return mutableAccount.getBalance(); + } + + @Override + public BytesValue getCode() { + return mutableAccount.getCode(); + } + + @Override + public Hash getCodeHash() { + return mutableAccount.getCodeHash(); + } + + @Override + public int getVersion() { + return mutableAccount.getVersion(); + } + + @Override + public UInt256 getStorageValue(final UInt256 key) { + return mutableAccount.getStorageValue(key); + } + + @Override + public UInt256 getOriginalStorageValue(final UInt256 key) { + return mutableAccount.getOriginalStorageValue(key); + } + + @Override + public NavigableMap storageEntriesFrom( + final Bytes32 startKeyHash, final int limit) { + throw new UnsupportedOperationException(); + } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java index 037018c871..2dfa520e1e 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java @@ -55,7 +55,8 @@ public MutableAccount getMutable(final Address address) { } final MutableAccount publicAccount = publicWorldUpdater.getMutable(address); if (publicAccount != null && !publicAccount.isEmpty()) { - return new ReadOnlyMutableAccount(publicAccount); + revert(); + return new ReadOnlyMutableAccount(publicAccount, publicWorldUpdater, privateWorldUpdater); } return null; } From 48f072069e94614a1eac4dc1be21d7a77ce012e6 Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Wed, 11 Sep 2019 12:17:06 +0100 Subject: [PATCH 05/10] Reverts properly when illegal operations are performed in private transactions/contracts --- .../tests/web3j/CrossContractReader.sol | 19 ++ .../web3j/generated/CrossContractReader.abi | 2 +- .../web3j/generated/CrossContractReader.bin | 2 +- .../web3j/generated/CrossContractReader.java | 314 ++++++++++++------ ...vateContractPublicStateAcceptanceTest.java | 79 ++++- .../ethereum/core/ReadOnlyMutableAccount.java | 181 +++++----- .../MainnetContractCreationProcessor.java | 24 +- .../operations/AbstractCreateOperation.java | 6 + .../vm/operations/SStoreOperation.java | 4 + .../vm/operations/SelfDestructOperation.java | 4 + ...efaultMutablePrivateWorldStateUpdater.java | 2 +- 11 files changed, 424 insertions(+), 213 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol index e13abee5bb..7df08c6f0d 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/CrossContractReader.sol @@ -19,6 +19,7 @@ import "./EventEmitter.sol"; // then create web3j wrappers with: // web3j solidity generate -b ./generated/CrossContractReader.bin -a ./generated/CrossContractReader.abi -o ../../../../../ -p tech.pegasys.pantheon.tests.web3j.generated contract CrossContractReader { + uint counter; event NewEventEmitter( address contractAddress @@ -38,4 +39,22 @@ contract CrossContractReader { CrossContractReader cross = CrossContractReader(crossAddress); cross.deploy(); } + + function increment() public { + counter++; + } + + function incrementRemote(address crossAddress) public { + CrossContractReader cross = CrossContractReader(crossAddress); + cross.increment(); + } + + function destroy() public { + selfdestruct(msg.sender); + } + + function remoteDestroy(address crossAddress) public { + CrossContractReader cross = CrossContractReader(crossAddress); + cross.destroy(); + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi index d58db9a1a9..36edfd6c59 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.abi @@ -1 +1 @@ -[{"constant":false,"inputs":[{"name":"crossAddress","type":"address"}],"name":"deployRemote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"deploy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"emitter_address","type":"address"}],"name":"read","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"contractAddress","type":"address"}],"name":"NewEventEmitter","type":"event"}] \ No newline at end of file +[{"constant":false,"inputs":[{"name":"crossAddress","type":"address"}],"name":"remoteDestroy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"crossAddress","type":"address"}],"name":"deployRemote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"deploy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"destroy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"emitter_address","type":"address"}],"name":"read","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"increment","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"crossAddress","type":"address"}],"name":"incrementRemote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"contractAddress","type":"address"}],"name":"NewEventEmitter","type":"event"}] \ No newline at end of file diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin index 4e023f660c..969f3c61b5 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b50610391806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80635374ded214610046578063775c300c1461006e578063a087a87e14610076575b600080fd5b61006c6004803603602081101561005c57600080fd5b50356001600160a01b03166100ae565b005b61006c61010a565b61009c6004803603602081101561008c57600080fd5b50356001600160a01b0316610178565b60408051918252519081900360200190f35b6000819050806001600160a01b031663775c300c6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156100ee57600080fd5b505af1158015610102573d6000803e3d6000fd5b505050505050565b6000604051610118906101ea565b604051809103906000f080158015610134573d6000803e3d6000fd5b50604080516001600160a01b038316815290519192507f9ac6876e0aa40667ffeaa9b359b5ed924f4cdd0e029eb6e9c369e78c68f711fb919081900360200190a150565b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b1580156101b757600080fd5b505afa1580156101cb573d6000803e3d6000fd5b505050506040513d60208110156101e157600080fd5b50519392505050565b610165806101f88339019056fe608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610133806100326000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fa4f2451460415780636057361d14605957806367e404ce146075575b600080fd5b60476097565b60408051918252519081900360200190f35b607360048036036020811015606d57600080fd5b5035609d565b005b607b60ef565b604080516001600160a01b039092168252519081900360200190f35b60025490565b604080513381526020810183905281517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb12b753f3d1aaa2d8f9f5929181900390910190a1600255600180546001600160a01b03191633179055565b6001546001600160a01b03169056fea265627a7a72305820964d6b1168cda84ea2a5bea18eef49bd496a1ff53f7be8178e00cca5dbec045764736f6c634300050a0032a265627a7a723058206bdfc638d14f0f26a6507f178968016fb2a0330e74accb27be8d6e302989fc3264736f6c634300050a0032 \ No newline at end of file +608060405234801561001057600080fd5b506104b7806100206000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c806383197ef01161005b57806383197ef0146100d8578063a087a87e146100e0578063d09de08a14610118578063e689ef8a146101205761007d565b8063305155f9146100825780635374ded2146100aa578063775c300c146100d0575b600080fd5b6100a86004803603602081101561009857600080fd5b50356001600160a01b0316610146565b005b6100a8600480360360208110156100c057600080fd5b50356001600160a01b03166101a2565b6100a86101e2565b6100a8610250565b610106600480360360208110156100f657600080fd5b50356001600160a01b0316610253565b60408051918252519081900360200190f35b6100a86102c5565b6100a86004803603602081101561013657600080fd5b50356001600160a01b03166102d0565b6000819050806001600160a01b03166383197ef06040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561018657600080fd5b505af115801561019a573d6000803e3d6000fd5b505050505050565b6000819050806001600160a01b031663775c300c6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561018657600080fd5b60006040516101f090610310565b604051809103906000f08015801561020c573d6000803e3d6000fd5b50604080516001600160a01b038316815290519192507f9ac6876e0aa40667ffeaa9b359b5ed924f4cdd0e029eb6e9c369e78c68f711fb919081900360200190a150565b33ff5b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b15801561029257600080fd5b505afa1580156102a6573d6000803e3d6000fd5b505050506040513d60208110156102bc57600080fd5b50519392505050565b600080546001019055565b6000819050806001600160a01b031663d09de08a6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561018657600080fd5b6101658061031e8339019056fe608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610133806100326000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fa4f2451460415780636057361d14605957806367e404ce146075575b600080fd5b60476097565b60408051918252519081900360200190f35b607360048036036020811015606d57600080fd5b5035609d565b005b607b60ef565b604080516001600160a01b039092168252519081900360200190f35b60025490565b604080513381526020810183905281517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb12b753f3d1aaa2d8f9f5929181900390910190a1600255600180546001600160a01b03191633179055565b6001546001600160a01b03169056fea265627a7a72305820964d6b1168cda84ea2a5bea18eef49bd496a1ff53f7be8178e00cca5dbec045764736f6c634300050a0032a265627a7a7230582079237493de0e17a01cb879d43a4a4eb29831a77717b1e156f133a8972139e94364736f6c634300050a0032 \ No newline at end of file diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java index 49bd7a9fc6..acb606a053 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/generated/CrossContractReader.java @@ -1,11 +1,24 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ package tech.pegasys.pantheon.tests.web3j.generated; -import io.reactivex.Flowable; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; + +import io.reactivex.Flowable; import org.web3j.abi.EventEncoder; import org.web3j.abi.TypeReference; import org.web3j.abi.datatypes.Address; @@ -25,136 +38,237 @@ import org.web3j.tx.gas.ContractGasProvider; /** - *

Auto generated code. + * Auto generated code. + * *

Do not modify! + * *

Please use the web3j command line tools, - * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the - * codegen module to update. + * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the codegen module to update. * *

Generated with web3j version 4.2.0. */ +@SuppressWarnings("rawtypes") public class CrossContractReader extends Contract { - private static final String BINARY = "608060405234801561001057600080fd5b50610391806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80635374ded214610046578063775c300c1461006e578063a087a87e14610076575b600080fd5b61006c6004803603602081101561005c57600080fd5b50356001600160a01b03166100ae565b005b61006c61010a565b61009c6004803603602081101561008c57600080fd5b50356001600160a01b0316610178565b60408051918252519081900360200190f35b6000819050806001600160a01b031663775c300c6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156100ee57600080fd5b505af1158015610102573d6000803e3d6000fd5b505050505050565b6000604051610118906101ea565b604051809103906000f080158015610134573d6000803e3d6000fd5b50604080516001600160a01b038316815290519192507f9ac6876e0aa40667ffeaa9b359b5ed924f4cdd0e029eb6e9c369e78c68f711fb919081900360200190a150565b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b1580156101b757600080fd5b505afa1580156101cb573d6000803e3d6000fd5b505050506040513d60208110156101e157600080fd5b50519392505050565b610165806101f88339019056fe608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610133806100326000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fa4f2451460415780636057361d14605957806367e404ce146075575b600080fd5b60476097565b60408051918252519081900360200190f35b607360048036036020811015606d57600080fd5b5035609d565b005b607b60ef565b604080516001600160a01b039092168252519081900360200190f35b60025490565b604080513381526020810183905281517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb12b753f3d1aaa2d8f9f5929181900390910190a1600255600180546001600160a01b03191633179055565b6001546001600160a01b03169056fea265627a7a72305820964d6b1168cda84ea2a5bea18eef49bd496a1ff53f7be8178e00cca5dbec045764736f6c634300050a0032a265627a7a723058206bdfc638d14f0f26a6507f178968016fb2a0330e74accb27be8d6e302989fc3264736f6c634300050a0032"; + private static final String BINARY = + "608060405234801561001057600080fd5b506104b7806100206000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c806383197ef01161005b57806383197ef0146100d8578063a087a87e146100e0578063d09de08a14610118578063e689ef8a146101205761007d565b8063305155f9146100825780635374ded2146100aa578063775c300c146100d0575b600080fd5b6100a86004803603602081101561009857600080fd5b50356001600160a01b0316610146565b005b6100a8600480360360208110156100c057600080fd5b50356001600160a01b03166101a2565b6100a86101e2565b6100a8610250565b610106600480360360208110156100f657600080fd5b50356001600160a01b0316610253565b60408051918252519081900360200190f35b6100a86102c5565b6100a86004803603602081101561013657600080fd5b50356001600160a01b03166102d0565b6000819050806001600160a01b03166383197ef06040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561018657600080fd5b505af115801561019a573d6000803e3d6000fd5b505050505050565b6000819050806001600160a01b031663775c300c6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561018657600080fd5b60006040516101f090610310565b604051809103906000f08015801561020c573d6000803e3d6000fd5b50604080516001600160a01b038316815290519192507f9ac6876e0aa40667ffeaa9b359b5ed924f4cdd0e029eb6e9c369e78c68f711fb919081900360200190a150565b33ff5b600080829050806001600160a01b0316633fa4f2456040518163ffffffff1660e01b815260040160206040518083038186803b15801561029257600080fd5b505afa1580156102a6573d6000803e3d6000fd5b505050506040513d60208110156102bc57600080fd5b50519392505050565b600080546001019055565b6000819050806001600160a01b031663d09de08a6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561018657600080fd5b6101658061031e8339019056fe608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610133806100326000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fa4f2451460415780636057361d14605957806367e404ce146075575b600080fd5b60476097565b60408051918252519081900360200190f35b607360048036036020811015606d57600080fd5b5035609d565b005b607b60ef565b604080516001600160a01b039092168252519081900360200190f35b60025490565b604080513381526020810183905281517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb12b753f3d1aaa2d8f9f5929181900390910190a1600255600180546001600160a01b03191633179055565b6001546001600160a01b03169056fea265627a7a72305820964d6b1168cda84ea2a5bea18eef49bd496a1ff53f7be8178e00cca5dbec045764736f6c634300050a0032a265627a7a7230582079237493de0e17a01cb879d43a4a4eb29831a77717b1e156f133a8972139e94364736f6c634300050a0032"; - public static final String FUNC_DEPLOYREMOTE = "deployRemote"; + public static final String FUNC_REMOTEDESTROY = "remoteDestroy"; - public static final String FUNC_READ = "read"; + public static final String FUNC_DEPLOYREMOTE = "deployRemote"; - public static final Event NEWEVENTEMITTER_EVENT = new Event("NewEventEmitter", - Arrays.>asList(new TypeReference

() {})); - ; + public static final String FUNC_DESTROY = "destroy"; - @Deprecated - protected CrossContractReader(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { - super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); - } + public static final String FUNC_READ = "read"; - protected CrossContractReader(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { - super(BINARY, contractAddress, web3j, credentials, contractGasProvider); - } + public static final String FUNC_INCREMENT = "increment"; - @Deprecated - protected CrossContractReader(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { - super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); - } + public static final String FUNC_INCREMENTREMOTE = "incrementRemote"; - protected CrossContractReader(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { - super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); - } + public static final Event NEWEVENTEMITTER_EVENT = + new Event( + "NewEventEmitter", Arrays.>asList(new TypeReference
() {}));; - public RemoteCall deployRemote(String crossAddress) { - final Function function = new Function( - FUNC_DEPLOYREMOTE, - Arrays.asList(new org.web3j.abi.datatypes.Address(crossAddress)), - Collections.>emptyList()); - return executeRemoteCallTransaction(function); - } + @Deprecated + protected CrossContractReader( + String contractAddress, + Web3j web3j, + Credentials credentials, + BigInteger gasPrice, + BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); + } - public RemoteCall deploy() { - final Function function = new Function( - FUNC_DEPLOY, - Arrays.asList(), - Collections.>emptyList()); - return executeRemoteCallTransaction(function); - } + protected CrossContractReader( + String contractAddress, + Web3j web3j, + Credentials credentials, + ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, credentials, contractGasProvider); + } - public RemoteCall read(String emitter_address) { - final Function function = new Function(FUNC_READ, - Arrays.asList(new org.web3j.abi.datatypes.Address(emitter_address)), - Arrays.>asList(new TypeReference() {})); - return executeRemoteCallSingleValueReturn(function, BigInteger.class); - } + @Deprecated + protected CrossContractReader( + String contractAddress, + Web3j web3j, + TransactionManager transactionManager, + BigInteger gasPrice, + BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + protected CrossContractReader( + String contractAddress, + Web3j web3j, + TransactionManager transactionManager, + ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); + } + + public RemoteCall remoteDestroy(String crossAddress) { + final Function function = + new Function( + FUNC_REMOTEDESTROY, + Arrays.asList(new org.web3j.abi.datatypes.Address(crossAddress)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } - public List getNewEventEmitterEvents(TransactionReceipt transactionReceipt) { - List valueList = extractEventParametersWithLog(NEWEVENTEMITTER_EVENT, transactionReceipt); - ArrayList responses = new ArrayList(valueList.size()); - for (Contract.EventValuesWithLog eventValues : valueList) { - NewEventEmitterEventResponse typedResponse = new NewEventEmitterEventResponse(); - typedResponse.log = eventValues.getLog(); - typedResponse.contractAddress = (String) eventValues.getNonIndexedValues().get(0).getValue(); - responses.add(typedResponse); - } - return responses; + public RemoteCall deployRemote(String crossAddress) { + final Function function = + new Function( + FUNC_DEPLOYREMOTE, + Arrays.asList(new org.web3j.abi.datatypes.Address(crossAddress)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteCall deploy() { + final Function function = + new Function(FUNC_DEPLOY, Arrays.asList(), Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteCall destroy() { + final Function function = + new Function( + FUNC_DESTROY, Arrays.asList(), Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteCall read(String emitter_address) { + final Function function = + new Function( + FUNC_READ, + Arrays.asList(new org.web3j.abi.datatypes.Address(emitter_address)), + Arrays.>asList(new TypeReference() {})); + return executeRemoteCallSingleValueReturn(function, BigInteger.class); + } + + public RemoteCall increment() { + final Function function = + new Function( + FUNC_INCREMENT, Arrays.asList(), Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteCall incrementRemote(String crossAddress) { + final Function function = + new Function( + FUNC_INCREMENTREMOTE, + Arrays.asList(new org.web3j.abi.datatypes.Address(crossAddress)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public List getNewEventEmitterEvents( + TransactionReceipt transactionReceipt) { + List valueList = + extractEventParametersWithLog(NEWEVENTEMITTER_EVENT, transactionReceipt); + ArrayList responses = + new ArrayList(valueList.size()); + for (Contract.EventValuesWithLog eventValues : valueList) { + NewEventEmitterEventResponse typedResponse = new NewEventEmitterEventResponse(); + typedResponse.log = eventValues.getLog(); + typedResponse.contractAddress = (String) eventValues.getNonIndexedValues().get(0).getValue(); + responses.add(typedResponse); } + return responses; + } - public Flowable newEventEmitterEventFlowable(EthFilter filter) { - return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function() { - @Override - public NewEventEmitterEventResponse apply(Log log) { - Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(NEWEVENTEMITTER_EVENT, log); + public Flowable newEventEmitterEventFlowable(EthFilter filter) { + return web3j + .ethLogFlowable(filter) + .map( + new io.reactivex.functions.Function() { + @Override + public NewEventEmitterEventResponse apply(Log log) { + Contract.EventValuesWithLog eventValues = + extractEventParametersWithLog(NEWEVENTEMITTER_EVENT, log); NewEventEmitterEventResponse typedResponse = new NewEventEmitterEventResponse(); typedResponse.log = log; - typedResponse.contractAddress = (String) eventValues.getNonIndexedValues().get(0).getValue(); + typedResponse.contractAddress = + (String) eventValues.getNonIndexedValues().get(0).getValue(); return typedResponse; - } - }); - } + } + }); + } - public Flowable newEventEmitterEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { - EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress()); - filter.addSingleTopic(EventEncoder.encode(NEWEVENTEMITTER_EVENT)); - return newEventEmitterEventFlowable(filter); - } + public Flowable newEventEmitterEventFlowable( + DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { + EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress()); + filter.addSingleTopic(EventEncoder.encode(NEWEVENTEMITTER_EVENT)); + return newEventEmitterEventFlowable(filter); + } - @Deprecated - public static CrossContractReader load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { - return new CrossContractReader(contractAddress, web3j, credentials, gasPrice, gasLimit); - } + @Deprecated + public static CrossContractReader load( + String contractAddress, + Web3j web3j, + Credentials credentials, + BigInteger gasPrice, + BigInteger gasLimit) { + return new CrossContractReader(contractAddress, web3j, credentials, gasPrice, gasLimit); + } - @Deprecated - public static CrossContractReader load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { - return new CrossContractReader(contractAddress, web3j, transactionManager, gasPrice, gasLimit); - } + @Deprecated + public static CrossContractReader load( + String contractAddress, + Web3j web3j, + TransactionManager transactionManager, + BigInteger gasPrice, + BigInteger gasLimit) { + return new CrossContractReader(contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } - public static CrossContractReader load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { - return new CrossContractReader(contractAddress, web3j, credentials, contractGasProvider); - } + public static CrossContractReader load( + String contractAddress, + Web3j web3j, + Credentials credentials, + ContractGasProvider contractGasProvider) { + return new CrossContractReader(contractAddress, web3j, credentials, contractGasProvider); + } - public static CrossContractReader load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { - return new CrossContractReader(contractAddress, web3j, transactionManager, contractGasProvider); - } + public static CrossContractReader load( + String contractAddress, + Web3j web3j, + TransactionManager transactionManager, + ContractGasProvider contractGasProvider) { + return new CrossContractReader(contractAddress, web3j, transactionManager, contractGasProvider); + } - public static RemoteCall deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { - return deployRemoteCall(CrossContractReader.class, web3j, credentials, contractGasProvider, BINARY, ""); - } + public static RemoteCall deploy( + Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { + return deployRemoteCall( + CrossContractReader.class, web3j, credentials, contractGasProvider, BINARY, ""); + } - @Deprecated - public static RemoteCall deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { - return deployRemoteCall(CrossContractReader.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); - } + @Deprecated + public static RemoteCall deploy( + Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + return deployRemoteCall( + CrossContractReader.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); + } - public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { - return deployRemoteCall(CrossContractReader.class, web3j, transactionManager, contractGasProvider, BINARY, ""); - } + public static RemoteCall deploy( + Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return deployRemoteCall( + CrossContractReader.class, web3j, transactionManager, contractGasProvider, BINARY, ""); + } - @Deprecated - public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { - return deployRemoteCall(CrossContractReader.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); - } + @Deprecated + public static RemoteCall deploy( + Web3j web3j, + TransactionManager transactionManager, + BigInteger gasPrice, + BigInteger gasLimit) { + return deployRemoteCall( + CrossContractReader.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); + } - public static class NewEventEmitterEventResponse { - public Log log; + public static class NewEventEmitterEventResponse { + public Log log; - public String contractAddress; - } + public String contractAddress; + } } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java index e2a06baf8f..254d5191c9 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java @@ -12,13 +12,9 @@ */ package tech.pegasys.pantheon.tests.web3j.privacy; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.web3j.protocol.core.methods.response.TransactionReceipt; -import org.web3j.protocol.eea.response.PrivateTransactionReceipt; -import org.web3j.tx.exceptions.ContractCallException; -import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNode; import tech.pegasys.pantheon.tests.web3j.generated.CrossContractReader; @@ -26,7 +22,12 @@ import java.math.BigInteger; -import static org.junit.Assert.assertNotNull; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.web3j.protocol.core.methods.response.TransactionReceipt; +import org.web3j.protocol.eea.response.PrivateTransactionReceipt; +import org.web3j.tx.exceptions.ContractCallException; public class PrivateContractPublicStateAcceptanceTest extends PrivacyAcceptanceTestBase { private static final long POW_CHAIN_ID = 2018; @@ -88,7 +89,32 @@ public void mustNotAllowAccessToPrivateStateFromPublicTx() throws Exception { } @Test - public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesContract() throws Exception { + public void privateContractMustNotBeAbleToCallPublicContractWhichChangesState() throws Exception { + CrossContractReader privateReader = + minerNode + .getPantheon() + .execute( + privateContractTransactions.createSmartContract( + CrossContractReader.class, + minerNode.getTransactionSigningKey(), + POW_CHAIN_ID, + minerNode.getEnclaveKey())); + + CrossContractReader publicReader = + minerNode + .getPantheon() + .execute(contractTransactions.createSmartContract(CrossContractReader.class)); + + var transactionReceipt = + (PrivateTransactionReceipt) + privateReader.incrementRemote(publicReader.getContractAddress()).send(); + + assertEquals("0x", transactionReceipt.getOutput()); + } + + @Test + public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesContract() + throws Exception { CrossContractReader privateReader = minerNode .getPantheon() @@ -99,11 +125,40 @@ public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesCon POW_CHAIN_ID, minerNode.getEnclaveKey())); - CrossContractReader publicReader = minerNode.getPantheon().execute(contractTransactions.createSmartContract(CrossContractReader.class)); + CrossContractReader publicReader = + minerNode + .getPantheon() + .execute(contractTransactions.createSmartContract(CrossContractReader.class)); + + var transactionReceipt = + (PrivateTransactionReceipt) + privateReader.deployRemote(publicReader.getContractAddress()).send(); + + assertEquals(0, transactionReceipt.getLogs().size()); + } + + @Test + public void privateContractMustNotBeAbleToCallPublicContractWhichSelfDestructs() + throws Exception { + CrossContractReader privateReader = + minerNode + .getPantheon() + .execute( + privateContractTransactions.createSmartContract( + CrossContractReader.class, + minerNode.getTransactionSigningKey(), + POW_CHAIN_ID, + minerNode.getEnclaveKey())); - var transactionReceipt = (PrivateTransactionReceipt) privateReader.deployRemote(publicReader.getContractAddress()).send(); + CrossContractReader publicReader = + minerNode + .getPantheon() + .execute(contractTransactions.createSmartContract(CrossContractReader.class)); + var transactionReceipt = + (PrivateTransactionReceipt) + privateReader.remoteDestroy(publicReader.getContractAddress()).send(); - //todo: result here is null which implies tx did not go through, but no error is encountered. + assertEquals("0x", transactionReceipt.getOutput()); } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java index 84308083a8..cc79790e42 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/ReadOnlyMutableAccount.java @@ -12,7 +12,6 @@ */ package tech.pegasys.pantheon.ethereum.core; -import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutablePrivateWorldStateUpdater; import tech.pegasys.pantheon.util.bytes.Bytes32; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.uint.UInt256; @@ -22,93 +21,95 @@ public class ReadOnlyMutableAccount implements MutableAccount { - private MutableAccount mutableAccount; - private final WorldUpdater publicWorldUpdater; - private final WorldUpdater privateWorldUpdater; - - public ReadOnlyMutableAccount(MutableAccount publicAccount, WorldUpdater publicWorldUpdater, WorldUpdater privateWorldUpdater) { - this.mutableAccount = publicAccount; - this.publicWorldUpdater = publicWorldUpdater; - this.privateWorldUpdater = privateWorldUpdater; - } - - @Override - public void setNonce(final long value) { - } - - @Override - public void setBalance(final Wei value) { - } - - @Override - public void setCode(final BytesValue code) { - } - - @Override - public void setVersion(final int version) { - } - - @Override - public void setStorageValue(final UInt256 key, final UInt256 value) { - } - - @Override - public void clearStorage() { - } - - @Override - public Map getUpdatedStorage() { - return mutableAccount.getUpdatedStorage(); - } - - @Override - public Address getAddress() { - return mutableAccount.getAddress(); - } - - @Override - public Hash getAddressHash() { - return mutableAccount.getAddressHash(); - } - - @Override - public long getNonce() { - return mutableAccount.getNonce(); - } - - @Override - public Wei getBalance() { - return mutableAccount.getBalance(); - } - - @Override - public BytesValue getCode() { - return mutableAccount.getCode(); - } - - @Override - public Hash getCodeHash() { - return mutableAccount.getCodeHash(); - } - - @Override - public int getVersion() { - return mutableAccount.getVersion(); - } - - @Override - public UInt256 getStorageValue(final UInt256 key) { - return mutableAccount.getStorageValue(key); - } - - @Override - public UInt256 getOriginalStorageValue(final UInt256 key) { - return mutableAccount.getOriginalStorageValue(key); - } - - @Override - public NavigableMap storageEntriesFrom( - final Bytes32 startKeyHash, final int limit) { - throw new UnsupportedOperationException(); - } + private MutableAccount mutableAccount; + + public ReadOnlyMutableAccount(final MutableAccount publicAccount) { + this.mutableAccount = publicAccount; + } + + @Override + public void setNonce(final long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setBalance(final Wei value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setCode(final BytesValue code) { + throw new UnsupportedOperationException(); + } + + @Override + public void setVersion(final int version) { + throw new UnsupportedOperationException(); + } + + @Override + public void setStorageValue(final UInt256 key, final UInt256 value) { + throw new UnsupportedOperationException(); + } + + @Override + public void clearStorage() { + throw new UnsupportedOperationException(); + } + + @Override + public Map getUpdatedStorage() { + return mutableAccount.getUpdatedStorage(); + } + + @Override + public Address getAddress() { + return mutableAccount.getAddress(); + } + + @Override + public Hash getAddressHash() { + return mutableAccount.getAddressHash(); + } + + @Override + public long getNonce() { + return mutableAccount.getNonce(); + } + + @Override + public Wei getBalance() { + return mutableAccount.getBalance(); + } + + @Override + public BytesValue getCode() { + return mutableAccount.getCode(); + } + + @Override + public Hash getCodeHash() { + return mutableAccount.getCodeHash(); + } + + @Override + public int getVersion() { + return mutableAccount.getVersion(); + } + + @Override + public UInt256 getStorageValue(final UInt256 key) { + return mutableAccount.getStorageValue(key); + } + + @Override + public UInt256 getOriginalStorageValue(final UInt256 key) { + return mutableAccount.getOriginalStorageValue(key); + } + + @Override + public NavigableMap storageEntriesFrom( + final Bytes32 startKeyHash, final int limit) { + throw new UnsupportedOperationException(); + } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java index 99b5dbe3e6..95d945ccc0 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java @@ -16,6 +16,7 @@ import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Gas; import tech.pegasys.pantheon.ethereum.core.MutableAccount; +import tech.pegasys.pantheon.ethereum.core.ReadOnlyMutableAccount; import tech.pegasys.pantheon.ethereum.vm.EVM; import tech.pegasys.pantheon.ethereum.vm.GasCalculator; import tech.pegasys.pantheon.ethereum.vm.MessageFrame; @@ -113,6 +114,9 @@ public void start(final MessageFrame frame) { "Contract creation error: account as already been created for address {}", frame.getContractAddress()); frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); + } else if (contract instanceof ReadOnlyMutableAccount) { + LOG.trace("Public contracts cannot be created from private calls"); + frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); } else { contract.incrementBalance(frame.getValue()); contract.setNonce(initialContractNonce); @@ -147,14 +151,18 @@ protected void codeSuccess(final MessageFrame frame) { // Finalize contract creation, setting the contract code. final MutableAccount contract = frame.getWorldState().getOrCreate(frame.getContractAddress()); - contract.setCode(contractCode); - contract.setVersion(accountVersion); - LOG.trace( - "Successful creation of contract {} with code of size {} (Gas remaining: {})", - frame.getContractAddress(), - contractCode.size(), - frame.getRemainingGas()); - frame.setState(MessageFrame.State.COMPLETED_SUCCESS); + if (!(contract instanceof ReadOnlyMutableAccount)) { + contract.setCode(contractCode); + contract.setVersion(accountVersion); + LOG.trace( + "Successful creation of contract {} with code of size {} (Gas remaining: {})", + frame.getContractAddress(), + contractCode.size(), + frame.getRemainingGas()); + frame.setState(MessageFrame.State.COMPLETED_SUCCESS); + } else { + frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); + } } else { frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/AbstractCreateOperation.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/AbstractCreateOperation.java index bb8a23c87e..011a0342aa 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/AbstractCreateOperation.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/AbstractCreateOperation.java @@ -15,6 +15,7 @@ import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Gas; import tech.pegasys.pantheon.ethereum.core.MutableAccount; +import tech.pegasys.pantheon.ethereum.core.ReadOnlyMutableAccount; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.vm.AbstractOperation; import tech.pegasys.pantheon.ethereum.vm.Code; @@ -89,6 +90,11 @@ private void fail(final MessageFrame frame) { private void spawnChildMessage(final MessageFrame frame) { final Address address = frame.getRecipientAddress(); final MutableAccount account = frame.getWorldState().getMutable(address); + if (account instanceof ReadOnlyMutableAccount) { + frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); + return; + } + account.incrementNonce(); final Wei value = Wei.wrap(frame.getStackItem(0)); diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/SStoreOperation.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/SStoreOperation.java index 2e81e21810..2e65599865 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/SStoreOperation.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/SStoreOperation.java @@ -15,6 +15,7 @@ import tech.pegasys.pantheon.ethereum.core.Account; import tech.pegasys.pantheon.ethereum.core.Gas; import tech.pegasys.pantheon.ethereum.core.MutableAccount; +import tech.pegasys.pantheon.ethereum.core.ReadOnlyMutableAccount; import tech.pegasys.pantheon.ethereum.vm.AbstractOperation; import tech.pegasys.pantheon.ethereum.vm.EVM; import tech.pegasys.pantheon.ethereum.vm.ExceptionalHaltReason; @@ -69,6 +70,9 @@ public Optional exceptionalHaltCondition( return Optional.of(ExceptionalHaltReason.ILLEGAL_STATE_CHANGE); } else if (frame.getRemainingGas().compareTo(minumumGasRemaining) < 0) { return Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS); + } else if (frame.getWorldState().getMutable(frame.getRecipientAddress()) + instanceof ReadOnlyMutableAccount) { + return Optional.of(ExceptionalHaltReason.ILLEGAL_STATE_CHANGE); } else { return Optional.empty(); } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/SelfDestructOperation.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/SelfDestructOperation.java index 41b35c37d9..3e4bee3437 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/SelfDestructOperation.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/operations/SelfDestructOperation.java @@ -16,6 +16,7 @@ import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Gas; import tech.pegasys.pantheon.ethereum.core.MutableAccount; +import tech.pegasys.pantheon.ethereum.core.ReadOnlyMutableAccount; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.vm.AbstractOperation; import tech.pegasys.pantheon.ethereum.vm.EVM; @@ -64,7 +65,10 @@ public Optional exceptionalHaltCondition( final MessageFrame frame, final EnumSet previousReasons, final EVM evm) { + return frame.isStatic() + || frame.getWorldState().getMutable(frame.getRecipientAddress()) + instanceof ReadOnlyMutableAccount ? Optional.of(ExceptionalHaltReason.ILLEGAL_STATE_CHANGE) : Optional.empty(); } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java index 2dfa520e1e..a3f248f7e1 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java @@ -56,7 +56,7 @@ public MutableAccount getMutable(final Address address) { final MutableAccount publicAccount = publicWorldUpdater.getMutable(address); if (publicAccount != null && !publicAccount.isEmpty()) { revert(); - return new ReadOnlyMutableAccount(publicAccount, publicWorldUpdater, privateWorldUpdater); + return new ReadOnlyMutableAccount(publicAccount); } return null; } From 4fce9fb3c621089aa0b019f4be585e0418233ed4 Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Wed, 11 Sep 2019 15:54:49 +0100 Subject: [PATCH 06/10] Fixes some bugs and tidies things up --- .../MainnetContractCreationProcessor.java | 20 ++++++++----------- .../privacy/PrivacyPrecompiledContract.java | 1 - .../privacy/PrivateTransactionProcessor.java | 6 +++--- ...efaultMutablePrivateWorldStateUpdater.java | 1 - 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java index 95d945ccc0..d139b28aee 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java @@ -151,18 +151,14 @@ protected void codeSuccess(final MessageFrame frame) { // Finalize contract creation, setting the contract code. final MutableAccount contract = frame.getWorldState().getOrCreate(frame.getContractAddress()); - if (!(contract instanceof ReadOnlyMutableAccount)) { - contract.setCode(contractCode); - contract.setVersion(accountVersion); - LOG.trace( - "Successful creation of contract {} with code of size {} (Gas remaining: {})", - frame.getContractAddress(), - contractCode.size(), - frame.getRemainingGas()); - frame.setState(MessageFrame.State.COMPLETED_SUCCESS); - } else { - frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); - } + contract.setCode(contractCode); + contract.setVersion(accountVersion); + LOG.trace( + "Successful creation of contract {} with code of size {} (Gas remaining: {})", + frame.getContractAddress(), + contractCode.size(), + frame.getRemainingGas()); + frame.setState(MessageFrame.State.COMPLETED_SUCCESS); } else { frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java index 72b614346e..6982437884 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java @@ -120,7 +120,6 @@ public BytesValue compute(final BytesValue input, final MessageFrame messageFram privateWorldStateArchive.getMutable(lastRootHash).get(); final WorldUpdater privateWorldStateUpdater = disposablePrivateState.updater(); - final PrivateTransactionProcessor.Result result = privateTransactionProcessor.processTransaction( messageFrame.getBlockchain(), diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionProcessor.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionProcessor.java index 9f645c9153..ff7840c279 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionProcessor.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionProcessor.java @@ -212,7 +212,7 @@ public Result processTransaction( final MessageFrame initialFrame; final Deque messageFrameStack = new ArrayDeque<>(); - final WorldUpdater mungedUpUpdater = + final WorldUpdater mutablePrivateWorldStateUpdater = new DefaultMutablePrivateWorldStateUpdater(publicWorldState, privateWorldState.updater()); if (transaction.isContractCreation()) { @@ -231,7 +231,7 @@ public Result processTransaction( .type(MessageFrame.Type.CONTRACT_CREATION) .messageFrameStack(messageFrameStack) .blockchain(blockchain) - .worldState(mungedUpUpdater) + .worldState(mutablePrivateWorldStateUpdater) .address(privateContractAddress) .originator(senderAddress) .contract(privateContractAddress) @@ -260,7 +260,7 @@ public Result processTransaction( .type(MessageFrame.Type.MESSAGE_CALL) .messageFrameStack(messageFrameStack) .blockchain(blockchain) - .worldState(mungedUpUpdater) + .worldState(mutablePrivateWorldStateUpdater) .address(to) .originator(senderAddress) .contract(to) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java index a3f248f7e1..037018c871 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/worldstate/DefaultMutablePrivateWorldStateUpdater.java @@ -55,7 +55,6 @@ public MutableAccount getMutable(final Address address) { } final MutableAccount publicAccount = publicWorldUpdater.getMutable(address); if (publicAccount != null && !publicAccount.isEmpty()) { - revert(); return new ReadOnlyMutableAccount(publicAccount); } return null; From 94525ef289cd6c997aa0dad5a0f175e7a207aa1c Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Wed, 11 Sep 2019 16:17:17 +0100 Subject: [PATCH 07/10] Fixes up test abstraction --- .../dsl/privacy/PrivacyAcceptanceTestBase.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java index e66f2ccf0f..71a2601331 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyAcceptanceTestBase.java @@ -12,21 +12,24 @@ */ package tech.pegasys.pantheon.tests.acceptance.dsl.privacy; -import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.net.NetConditions; import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.privacy.PrivacyNodeFactory; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.account.PrivacyAccountResolver; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.condition.PrivateContractVerifier; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.condition.PrivateTransactionVerifier; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.contract.PrivateContractTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.transaction.PrivacyTransactions; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.contract.ContractTransactions; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetTransactions; import org.junit.After; import org.junit.ClassRule; import org.junit.rules.TemporaryFolder; -public class PrivacyAcceptanceTestBase extends AcceptanceTestBase { +public class PrivacyAcceptanceTestBase { @ClassRule public static final TemporaryFolder privacy = new TemporaryFolder(); + protected final NetConditions net; protected final PrivacyTransactions privacyTransactions; protected final PrivateContractVerifier privateContractVerifier; protected final PrivateTransactionVerifier privateTransactionVerifier; @@ -34,9 +37,10 @@ public class PrivacyAcceptanceTestBase extends AcceptanceTestBase { protected final PrivateContractTransactions privateContractTransactions; protected final PrivacyCluster privacyCluster; protected final PrivacyAccountResolver privacyAccountResolver; + protected final ContractTransactions contractTransactions; public PrivacyAcceptanceTestBase() { - super(); + net = new NetConditions(new NetTransactions()); privacyTransactions = new PrivacyTransactions(); privateContractVerifier = new PrivateContractVerifier(); privateTransactionVerifier = new PrivateTransactionVerifier(privacyTransactions); @@ -44,12 +48,11 @@ public PrivacyAcceptanceTestBase() { privateContractTransactions = new PrivateContractTransactions(); privacyCluster = new PrivacyCluster(net); privacyAccountResolver = new PrivacyAccountResolver(); + contractTransactions = new ContractTransactions(); } - @Override @After public void tearDownAcceptanceTestBase() { - cluster.close(); privacyCluster.close(); } } From 02016515f5f94d97afa12a1aad08d24183990966 Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Wed, 11 Sep 2019 23:39:57 +0100 Subject: [PATCH 08/10] Addresses PR comments --- ...vateContractPublicStateAcceptanceTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java index 254d5191c9..bf50d3707a 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java @@ -52,7 +52,7 @@ public void mustAllowAccessToPublicStateFromPrivateTx() throws Exception { final TransactionReceipt receipt = publicEventEmitter.store(BigInteger.valueOf(12)).send(); assertNotNull(receipt); - CrossContractReader reader = + final CrossContractReader reader = minerNode .getPantheon() .execute( @@ -80,7 +80,7 @@ public void mustNotAllowAccessToPrivateStateFromPublicTx() throws Exception { final TransactionReceipt receipt = privateEventEmitter.store(BigInteger.valueOf(12)).send(); assertNotNull(receipt); - CrossContractReader publicReader = + final CrossContractReader publicReader = minerNode .getPantheon() .execute(contractTransactions.createSmartContract(CrossContractReader.class)); @@ -90,7 +90,7 @@ public void mustNotAllowAccessToPrivateStateFromPublicTx() throws Exception { @Test public void privateContractMustNotBeAbleToCallPublicContractWhichChangesState() throws Exception { - CrossContractReader privateReader = + final CrossContractReader privateReader = minerNode .getPantheon() .execute( @@ -100,12 +100,12 @@ public void privateContractMustNotBeAbleToCallPublicContractWhichChangesState() POW_CHAIN_ID, minerNode.getEnclaveKey())); - CrossContractReader publicReader = + final CrossContractReader publicReader = minerNode .getPantheon() .execute(contractTransactions.createSmartContract(CrossContractReader.class)); - var transactionReceipt = + final PrivateTransactionReceipt transactionReceipt = (PrivateTransactionReceipt) privateReader.incrementRemote(publicReader.getContractAddress()).send(); @@ -115,7 +115,7 @@ public void privateContractMustNotBeAbleToCallPublicContractWhichChangesState() @Test public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesContract() throws Exception { - CrossContractReader privateReader = + final CrossContractReader privateReader = minerNode .getPantheon() .execute( @@ -125,12 +125,12 @@ public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesCon POW_CHAIN_ID, minerNode.getEnclaveKey())); - CrossContractReader publicReader = + final CrossContractReader publicReader = minerNode .getPantheon() .execute(contractTransactions.createSmartContract(CrossContractReader.class)); - var transactionReceipt = + final PrivateTransactionReceipt transactionReceipt = (PrivateTransactionReceipt) privateReader.deployRemote(publicReader.getContractAddress()).send(); @@ -140,7 +140,7 @@ public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesCon @Test public void privateContractMustNotBeAbleToCallPublicContractWhichSelfDestructs() throws Exception { - CrossContractReader privateReader = + final CrossContractReader privateReader = minerNode .getPantheon() .execute( @@ -150,12 +150,12 @@ public void privateContractMustNotBeAbleToCallPublicContractWhichSelfDestructs() POW_CHAIN_ID, minerNode.getEnclaveKey())); - CrossContractReader publicReader = + final CrossContractReader publicReader = minerNode .getPantheon() .execute(contractTransactions.createSmartContract(CrossContractReader.class)); - var transactionReceipt = + final PrivateTransactionReceipt transactionReceipt = (PrivateTransactionReceipt) privateReader.remoteDestroy(publicReader.getContractAddress()).send(); From 172cde1f7dc83aa985999fac9fed8a65b336813e Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Thu, 12 Sep 2019 09:11:03 +0100 Subject: [PATCH 09/10] Spotless --- .../privacy/PrivateContractPublicStateAcceptanceTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java index bf50d3707a..e192651cc9 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivateContractPublicStateAcceptanceTest.java @@ -138,8 +138,7 @@ public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesCon } @Test - public void privateContractMustNotBeAbleToCallPublicContractWhichSelfDestructs() - throws Exception { + public void privateContractMustNotBeAbleToCallSelfDetructOfPublicContract() throws Exception { final CrossContractReader privateReader = minerNode .getPantheon() From 06e98e7fc7ddd1ac0572a922ee1e571992baeebd Mon Sep 17 00:00:00 2001 From: Joshua Richardson Date: Fri, 13 Sep 2019 10:11:08 +0100 Subject: [PATCH 10/10] Addresses PR comments --- .../ethereum/mainnet/MainnetContractCreationProcessor.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java index d139b28aee..2d1d5fa4d1 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetContractCreationProcessor.java @@ -114,9 +114,6 @@ public void start(final MessageFrame frame) { "Contract creation error: account as already been created for address {}", frame.getContractAddress()); frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); - } else if (contract instanceof ReadOnlyMutableAccount) { - LOG.trace("Public contracts cannot be created from private calls"); - frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); } else { contract.incrementBalance(frame.getValue()); contract.setNonce(initialContractNonce);