Make sure that the onchain privacy group version is always different. (#828)

* Make sure that the onchain privacy group version is always different.

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
pull/839/head
Stefan Pingel 5 years ago committed by GitHub
parent c657ca7187
commit 46233966f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivacyRequestFactory.java
  2. 6
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/web3j/privacy/OnChainPrivacyAcceptanceTest.java
  3. 2
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/web3j/privacy/PrivCallAcceptanceTest.java
  4. 38
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/web3j/privacy/contracts/PrivacyGroupTest.java
  5. 63
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/web3j/privacy/contracts/PrivacyProxyTest.java
  6. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java
  7. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java
  8. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java
  9. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java
  10. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Address.java
  11. 31
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContract.java
  12. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyController.java
  13. 12
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateGroupRehydrationBlockProcessor.java
  14. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/group/OnChainGroupManagement.java
  15. 80
      privacy-contracts/src/main/java/org/hyperledger/besu/privacy/contracts/generated/DefaultOnChainPrivacyGroupManagementContract.java
  16. 77
      privacy-contracts/src/main/java/org/hyperledger/besu/privacy/contracts/generated/OnChainPrivacyGroupManagementInterface.java
  17. 68
      privacy-contracts/src/main/java/org/hyperledger/besu/privacy/contracts/generated/OnChainPrivacyGroupManagementProxy.java
  18. 14
      privacy-contracts/src/main/solidity/DefaultOnChainPrivacyGroupManagementContract.sol
  19. 2
      privacy-contracts/src/main/solidity/OnChainPrivacyGroupManagementInterface.sol
  20. 2
      privacy-contracts/src/main/solidity/OnChainPrivacyGroupManagementProxy.sol
  21. 1
      privacy-contracts/src/main/solidity/generateWrappers.sh

@ -146,7 +146,7 @@ public class PrivacyRequestFactory {
nonce,
BigInteger.valueOf(1000),
BigInteger.valueOf(3000000),
Address.PRIVACY_PROXY.toHexString(),
Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
payload.toHexString(),
Base64String.wrap(adder.getEnclaveKey()),
privacyGroupId,
@ -180,7 +180,7 @@ public class PrivacyRequestFactory {
nonce,
BigInteger.valueOf(1000),
BigInteger.valueOf(3000000),
Address.PRIVACY_PROXY.toHexString(),
Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
payload.toHexString(),
Base64String.wrap(remover.getEnclaveKey()),
privacyGroupId,
@ -213,7 +213,7 @@ public class PrivacyRequestFactory {
nonce,
BigInteger.valueOf(1000),
BigInteger.valueOf(3000000),
Address.PRIVACY_PROXY.toHexString(),
Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
OnChainGroupManagement.LOCK_GROUP_METHOD_SIGNATURE.toHexString(),
Base64String.wrap(locker.getEnclaveKey()),
privacyGroupId,
@ -262,7 +262,7 @@ public class PrivacyRequestFactory {
nonce,
BigInteger.valueOf(1000),
BigInteger.valueOf(3000000),
Address.PRIVACY_PROXY.toHexString(),
Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
payload.toHexString(),
Base64String.wrap(creator.getEnclaveKey()),
Base64String.wrap(privacyGroupId.toArrayUnsafe()),

@ -330,7 +330,7 @@ public class OnChainPrivacyAcceptanceTest extends PrivacyAcceptanceTestBase {
new PrivateTransactionReceipt(
null,
alice.getAddress().toHexString(),
Address.PRIVACY_PROXY.toHexString(),
Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
"0x",
Collections.emptyList(),
null,
@ -503,7 +503,7 @@ public class OnChainPrivacyAcceptanceTest extends PrivacyAcceptanceTestBase {
final String privacyGroupId, final PrivacyNode groupCreator) {
return groupCreator.execute(
privateContractTransactions.callOnChainPermissioningSmartContract(
Address.PRIVACY_PROXY.toHexString(),
Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
GET_PARTICIPANTS_METHOD_SIGNATURE
+ Bytes.fromBase64String(groupCreator.getEnclaveKey()).toUnprefixedHexString(),
groupCreator.getTransactionSigningKey(),
@ -529,7 +529,7 @@ public class OnChainPrivacyAcceptanceTest extends PrivacyAcceptanceTestBase {
return new PrivateTransactionReceipt(
null,
groupCreator.getAddress().toHexString(),
Address.PRIVACY_PROXY.toHexString(),
Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
output.toString(),
Collections.emptyList(),
null,

@ -113,8 +113,6 @@ public class PrivCallAcceptanceTest extends PrivacyAcceptanceTestBase {
minerNode.getEnclaveKey(),
privacyGroupId));
System.out.println("Address: " + eventEmitter.getContractAddress());
privateContractVerifier
.validPrivateContractDeployed(
eventEmitter.getContractAddress(), minerNode.getAddress().toString())

@ -16,11 +16,10 @@ package org.hyperledger.besu.tests.web3j.privacy.contracts;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.privacy.contracts.generated.PrivacyGroup;
import org.hyperledger.besu.privacy.contracts.generated.DefaultOnChainPrivacyGroupManagementContract;
import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
@ -38,7 +37,7 @@ public class PrivacyGroupTest extends AcceptanceTestBase {
Base64String.wrap("Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=");
private final Base64String thirdParticipant =
Base64String.wrap("Jo2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=");
private PrivacyGroup privacyGroup;
private DefaultOnChainPrivacyGroupManagementContract privacyGroup;
private static final String RAW_FIRST_PARTICIPANT =
"0x0b0235be035695b4cc4b0941e60551d7a19cf30603db5bfc23e5ac43a56f57f25f75486a";
@ -57,7 +56,10 @@ public class PrivacyGroupTest extends AcceptanceTestBase {
public void setUp() throws Exception {
minerNode = besu.createMinerNode("node");
cluster.start(minerNode);
privacyGroup = minerNode.execute(contractTransactions.createSmartContract(PrivacyGroup.class));
privacyGroup =
minerNode.execute(
contractTransactions.createSmartContract(
DefaultOnChainPrivacyGroupManagementContract.class));
}
@Test
@ -131,6 +133,26 @@ public class PrivacyGroupTest extends AcceptanceTestBase {
assertThat(privacyGroup.canExecute().send()).isTrue();
}
@Test
public void ensurePrivacyGroupVersionIsAlwaysDifferent() throws Exception {
privacyGroup
.addParticipants(firstParticipant.raw(), Collections.singletonList(secondParticipant.raw()))
.send();
final byte[] version1 = privacyGroup.getVersion().send();
privacyGroup.lock().send();
privacyGroup
.addParticipants(firstParticipant.raw(), Collections.singletonList(thirdParticipant.raw()))
.send();
final byte[] version2 = privacyGroup.getVersion().send();
privacyGroup.lock().send();
privacyGroup.removeParticipant(firstParticipant.raw(), secondParticipant.raw()).send();
final byte[] version3 = privacyGroup.getVersion().send();
assertThat(version1).isNotEqualTo(version2);
assertThat(version1).isNotEqualTo(version3);
assertThat(version2).isNotEqualTo(version3);
}
@Test
public void canAddTwiceToContractWhenCallLock() throws Exception {
privacyGroup
@ -140,8 +162,6 @@ public class PrivacyGroupTest extends AcceptanceTestBase {
privacyGroup
.addParticipants(firstParticipant.raw(), Collections.singletonList(secondParticipant.raw()))
.send();
final BigInteger privacyGroupVersion = privacyGroup.getVersion().send();
assertThat(privacyGroupVersion).isEqualTo(BigInteger.TWO);
final List<byte[]> participants = privacyGroup.getParticipants(firstParticipant.raw()).send();
assertThat(participants.size()).isEqualTo(3);
@ -150,12 +170,6 @@ public class PrivacyGroupTest extends AcceptanceTestBase {
assertThat(secondParticipant.raw()).isEqualTo(participants.get(2));
}
@Test
public void versionStartsAtZero() throws Exception {
final BigInteger privacyGroupVersion = privacyGroup.getVersion().send();
assertThat(privacyGroupVersion).isEqualTo(BigInteger.ZERO);
}
@Test(expected = TransactionException.class)
public void cannotLockTwice() throws Exception {
privacyGroup

@ -16,8 +16,8 @@ package org.hyperledger.besu.tests.web3j.privacy.contracts;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.privacy.contracts.generated.PrivacyGroup;
import org.hyperledger.besu.privacy.contracts.generated.PrivacyProxy;
import org.hyperledger.besu.privacy.contracts.generated.DefaultOnChainPrivacyGroupManagementContract;
import org.hyperledger.besu.privacy.contracts.generated.OnChainPrivacyGroupManagementProxy;
import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
@ -38,7 +38,7 @@ public class PrivacyProxyTest extends AcceptanceTestBase {
Base64String.wrap("9iaJ6OObl6TUWYjXAOyZsL0VaDPwF+tRFkMwwYSeqqw=");
private final Base64String thirdParticipant =
Base64String.wrap("Jo2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=");
private PrivacyProxy privacyProxy;
private OnChainPrivacyGroupManagementProxy onChainPrivacyGroupManagementProxy;
private static final String RAW_FIRST_PARTICIPANT =
"0x0b0235bef772b2ee55f016431cefe724a05814324bb96e9afdb73e338665a693d4653678";
@ -51,27 +51,32 @@ public class PrivacyProxyTest extends AcceptanceTestBase {
public void setUp() throws Exception {
minerNode = besu.createMinerNode("node");
cluster.start(minerNode);
PrivacyGroup privacyGroup =
minerNode.execute(contractTransactions.createSmartContract(PrivacyGroup.class));
privacyProxy =
DefaultOnChainPrivacyGroupManagementContract privacyGroup =
minerNode.execute(
contractTransactions.createSmartContract(
PrivacyProxy.class, privacyGroup.getContractAddress()));
DefaultOnChainPrivacyGroupManagementContract.class));
onChainPrivacyGroupManagementProxy =
minerNode.execute(
contractTransactions.createSmartContract(
OnChainPrivacyGroupManagementProxy.class, privacyGroup.getContractAddress()));
}
@Test
public void rlp() throws Exception {
assertThat(privacyProxy.isValid()).isEqualTo(true);
assertThat(onChainPrivacyGroupManagementProxy.isValid()).isEqualTo(true);
contractVerifier
.validTransactionReceipt(privacyProxy.getContractAddress())
.verify(privacyProxy);
.validTransactionReceipt(onChainPrivacyGroupManagementProxy.getContractAddress())
.verify(onChainPrivacyGroupManagementProxy);
// 0x0b0235be
assertThat(RAW_FIRST_PARTICIPANT)
.isEqualTo(privacyProxy.getParticipants(firstParticipant.raw()).encodeFunctionCall());
.isEqualTo(
onChainPrivacyGroupManagementProxy
.getParticipants(firstParticipant.raw())
.encodeFunctionCall());
// 0xf744b089
assertThat(RAW_ADD_PARTICIPANT)
.isEqualTo(
privacyProxy
onChainPrivacyGroupManagementProxy
.addParticipants(firstParticipant.raw(), Collections.emptyList())
.encodeFunctionCall());
}
@ -79,16 +84,18 @@ public class PrivacyProxyTest extends AcceptanceTestBase {
@Ignore("return 0x which causes web3j to throw exception instead of return empty list")
@Test
public void deploysWithNoParticipant() throws Exception {
final List<byte[]> participants = privacyProxy.getParticipants(firstParticipant.raw()).send();
final List<byte[]> participants =
onChainPrivacyGroupManagementProxy.getParticipants(firstParticipant.raw()).send();
assertThat(participants.size()).isEqualTo(0);
}
@Test
public void canAddParticipants() throws Exception {
privacyProxy
onChainPrivacyGroupManagementProxy
.addParticipants(firstParticipant.raw(), Collections.singletonList(secondParticipant.raw()))
.send();
final List<byte[]> participants = privacyProxy.getParticipants(firstParticipant.raw()).send();
final List<byte[]> participants =
onChainPrivacyGroupManagementProxy.getParticipants(firstParticipant.raw()).send();
assertThat(participants.size()).isEqualTo(2);
assertThat(firstParticipant.raw()).isEqualTo(participants.get(0));
assertThat(secondParticipant.raw()).isEqualTo(participants.get(1));
@ -96,23 +103,26 @@ public class PrivacyProxyTest extends AcceptanceTestBase {
@Test
public void canUpgrade() throws Exception {
privacyProxy
onChainPrivacyGroupManagementProxy
.addParticipants(firstParticipant.raw(), Collections.singletonList(secondParticipant.raw()))
.send();
final List<byte[]> participants = privacyProxy.getParticipants(firstParticipant.raw()).send();
final List<byte[]> participants =
onChainPrivacyGroupManagementProxy.getParticipants(firstParticipant.raw()).send();
assertThat(participants.size()).isEqualTo(2);
assertThat(firstParticipant.raw()).isEqualTo(participants.get(0));
assertThat(secondParticipant.raw()).isEqualTo(participants.get(1));
final PrivacyGroup upgradedContract =
minerNode.execute(contractTransactions.createSmartContract(PrivacyGroup.class));
final DefaultOnChainPrivacyGroupManagementContract upgradedContract =
minerNode.execute(
contractTransactions.createSmartContract(
DefaultOnChainPrivacyGroupManagementContract.class));
privacyProxy.upgradeTo(upgradedContract.getContractAddress()).send();
privacyProxy
onChainPrivacyGroupManagementProxy.upgradeTo(upgradedContract.getContractAddress()).send();
onChainPrivacyGroupManagementProxy
.addParticipants(firstParticipant.raw(), Collections.singletonList(secondParticipant.raw()))
.send();
final List<byte[]> participantsAfterUpgrade =
privacyProxy.getParticipants(firstParticipant.raw()).send();
onChainPrivacyGroupManagementProxy.getParticipants(firstParticipant.raw()).send();
assertThat(participantsAfterUpgrade.size()).isEqualTo(2);
assertThat(firstParticipant.raw()).isEqualTo(participantsAfterUpgrade.get(0));
assertThat(secondParticipant.raw()).isEqualTo(participantsAfterUpgrade.get(1));
@ -120,14 +130,15 @@ public class PrivacyProxyTest extends AcceptanceTestBase {
@Test
public void canAddTwiceToContractWhenCallLock() throws Exception {
privacyProxy
onChainPrivacyGroupManagementProxy
.addParticipants(firstParticipant.raw(), Collections.singletonList(thirdParticipant.raw()))
.send();
privacyProxy.lock().send();
privacyProxy
onChainPrivacyGroupManagementProxy.lock().send();
onChainPrivacyGroupManagementProxy
.addParticipants(firstParticipant.raw(), Collections.singletonList(secondParticipant.raw()))
.send();
final List<byte[]> participants = privacyProxy.getParticipants(firstParticipant.raw()).send();
final List<byte[]> participants =
onChainPrivacyGroupManagementProxy.getParticipants(firstParticipant.raw()).send();
assertThat(participants.size()).isEqualTo(3);
assertThat(firstParticipant.raw()).isEqualTo(participants.get(0));
assertThat(thirdParticipant.raw()).isEqualTo(participants.get(1));

@ -90,7 +90,7 @@ public class EeaSendRawTransaction implements JsonRpcMethod {
final Optional<Bytes> maybePrivacyGroupId = privateTransaction.getPrivacyGroupId();
if (onchainPrivacyGroupsEnabled) {
if (!maybePrivacyGroupId.isPresent()) {
return new JsonRpcErrorResponse(id, JsonRpcError.PRIVACY_GROUP_ID_NOT_AVAILABLE);
return new JsonRpcErrorResponse(id, JsonRpcError.ONCHAIN_PRIVACY_GROUP_ID_NOT_AVAILABLE);
}
maybePrivacyGroup =
privacyController.retrieveOnChainPrivacyGroup(

@ -85,7 +85,7 @@ public class PrivDistributeRawTransaction implements JsonRpcMethod {
final Optional<Bytes> maybePrivacyGroupId = privateTransaction.getPrivacyGroupId();
if (onchainPrivacyGroupsEnabled) {
if (!maybePrivacyGroupId.isPresent()) {
return new JsonRpcErrorResponse(id, JsonRpcError.PRIVACY_GROUP_ID_NOT_AVAILABLE);
return new JsonRpcErrorResponse(id, JsonRpcError.ONCHAIN_PRIVACY_GROUP_ID_NOT_AVAILABLE);
}
maybePrivacyGroup =
privacyController.retrieveOnChainPrivacyGroup(

@ -120,8 +120,8 @@ public enum JsonRpcError {
ONCHAIN_PRIVACY_GROUP_NOT_ENABLED(-50100, "Onchain privacy groups not enabled."),
OFFCHAIN_PRIVACY_GROUP_NOT_ENABLED(
-50100, "Offchain privacy group can't be used with Onchain privacy groups enabled."),
PRIVACY_GROUP_ID_NOT_AVAILABLE(
-50100, "Privacy group id is not available while OnChain privacy groups are enabled"),
ONCHAIN_PRIVACY_GROUP_ID_NOT_AVAILABLE(
-50100, "Private transactions to on-chain privacy groups must use privacyGroupId"),
PRIVATE_FROM_DOES_NOT_MATCH_ENCLAVE_PUBLIC_KEY(
-50100, "Private from does not match enclave public key"),
PMT_FAILED_INTRINSIC_GAS_EXCEEDS_LIMIT(

@ -308,7 +308,7 @@ public class EeaSendRawTransactionTest {
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(
request.getRequest().getId(), JsonRpcError.PRIVACY_GROUP_ID_NOT_AVAILABLE);
request.getRequest().getId(), JsonRpcError.ONCHAIN_PRIVACY_GROUP_ID_NOT_AVAILABLE);
final JsonRpcResponse actualResponse = method.response(request);

@ -46,8 +46,10 @@ public class Address extends DelegatingBytes implements org.hyperledger.besu.plu
public static final Integer PRIVACY = Byte.MAX_VALUE - 1;
public static final Address DEFAULT_PRIVACY = Address.precompiled(PRIVACY);
public static final Address ONCHAIN_PRIVACY = Address.precompiled(PRIVACY - 1);
public static final Address PRIVACY_PROXY = Address.precompiled(PRIVACY - 2);
public static final Address DEFAULT_PRIVACY_MANAGEMENT = Address.precompiled(PRIVACY - 3);
// Onchain privacy management contracts (injected in private state)
public static final Address ONCHAIN_PRIVACY_PROXY = Address.precompiled(PRIVACY - 2);
public static final Address DEFAULT_ONCHAIN_PRIVACY_MANAGEMENT = Address.precompiled(PRIVACY - 3);
public static final Address ZERO = Address.fromHexString("0x0");

@ -228,7 +228,7 @@ public class OnChainPrivacyPrecompiledContract extends PrivacyPrecompiledContrac
final MutableWorldState disposablePrivateState,
final WorldUpdater privateWorldStateUpdater) {
final PrivateTransactionProcessor.Result result =
checkCanExecute(
simulateTransaction(
messageFrame,
currentBlockHeader,
publicWorldState,
@ -240,7 +240,7 @@ public class OnChainPrivacyPrecompiledContract extends PrivacyPrecompiledContrac
return result.getOutput().toHexString().endsWith("0");
}
protected PrivateTransactionProcessor.Result checkCanExecute(
protected PrivateTransactionProcessor.Result simulateTransaction(
final MessageFrame messageFrame,
final ProcessableBlockHeader currentBlockHeader,
final WorldUpdater publicWorldState,
@ -248,23 +248,22 @@ public class OnChainPrivacyPrecompiledContract extends PrivacyPrecompiledContrac
final Blockchain currentBlockchain,
final MutableWorldState disposablePrivateState,
final WorldUpdater privateWorldStateUpdater,
final Bytes canExecuteMethodSignature) {
final Bytes methodSignature) {
// We need the "lock status" of the group for every single transaction but we don't want this
// call to affect the state
// privateTransactionProcessor.processTransaction(...) commits the state if the process was
// successful before it returns
final MutableWorldState canExecutePrivateState =
final MutableWorldState localMutableState =
privateWorldStateArchive.getMutable(disposablePrivateState.rootHash()).get();
final WorldUpdater canExecuteUpdater = canExecutePrivateState.updater();
final WorldUpdater updater = localMutableState.updater();
return privateTransactionProcessor.processTransaction(
currentBlockchain,
publicWorldState,
canExecuteUpdater,
updater,
currentBlockHeader,
messageFrame.getTransactionHash(),
buildSimulationTransaction(
privacyGroupId, privateWorldStateUpdater, canExecuteMethodSignature),
buildSimulationTransaction(privacyGroupId, privateWorldStateUpdater, methodSignature),
messageFrame.getMiningBeneficiary(),
new DebugOperationTracer(TraceOptions.DEFAULT),
messageFrame.getBlockHashLookup(),
@ -278,20 +277,22 @@ public class OnChainPrivacyPrecompiledContract extends PrivacyPrecompiledContrac
if (lastRootHash.equals(EMPTY_ROOT_HASH)) {
// inject management
final DefaultEvmAccount managementPrecompile =
privateWorldStateUpdater.createAccount(Address.DEFAULT_PRIVACY_MANAGEMENT);
privateWorldStateUpdater.createAccount(Address.DEFAULT_ONCHAIN_PRIVACY_MANAGEMENT);
final MutableAccount mutableManagementPrecompiled = managementPrecompile.getMutable();
// this is the code for the simple management contract
mutableManagementPrecompiled.setCode(OnChainGroupManagement.DEFAULT_GROUP_MANAGEMENT_CODE);
mutableManagementPrecompiled.setCode(
OnChainGroupManagement.DEFAULT_GROUP_MANAGEMENT_RUNTIME_BYTECODE);
// inject proxy
final DefaultEvmAccount proxyPrecompile =
privateWorldStateUpdater.createAccount(Address.PRIVACY_PROXY);
privateWorldStateUpdater.createAccount(Address.ONCHAIN_PRIVACY_PROXY);
final MutableAccount mutableProxyPrecompiled = proxyPrecompile.getMutable();
// this is the code for the proxy contract
mutableProxyPrecompiled.setCode(OnChainGroupManagement.DEFAULT_PROXY_PRECOMPILED_CODE);
mutableProxyPrecompiled.setCode(OnChainGroupManagement.PROXY_RUNTIME_BYTECODE);
// manually set the management contract address so the proxy can trust it
mutableProxyPrecompiled.setStorageValue(
UInt256.ZERO, UInt256.fromBytes(Bytes32.leftPad(Address.DEFAULT_PRIVACY_MANAGEMENT)));
UInt256.ZERO,
UInt256.fromBytes(Bytes32.leftPad(Address.DEFAULT_ONCHAIN_PRIVACY_MANAGEMENT)));
privateWorldStateUpdater.commit();
disposablePrivateState.persist();
@ -312,7 +313,7 @@ public class OnChainPrivacyPrecompiledContract extends PrivacyPrecompiledContrac
// privateTransactionProcessor.processTransaction(...) commits the state if the process was
// successful before it returns
final PrivateTransactionProcessor.Result getVersionResult =
checkCanExecute(
simulateTransaction(
messageFrame,
currentBlockHeader,
publicWorldState,
@ -348,7 +349,7 @@ public class OnChainPrivacyPrecompiledContract extends PrivacyPrecompiledContrac
: 0)
.gasPrice(Wei.of(1000))
.gasLimit(3000000)
.to(Address.PRIVACY_PROXY)
.to(Address.ONCHAIN_PRIVACY_PROXY)
.sender(Address.ZERO)
.value(Wei.ZERO)
.payload(payload)

@ -321,7 +321,7 @@ public class DefaultPrivacyController implements PrivacyController {
private CallParameter buildCallParams(final Bytes enclavePublicKey, final Bytes methodCall) {
return new CallParameter(
Address.ZERO,
Address.PRIVACY_PROXY,
Address.ONCHAIN_PRIVACY_PROXY,
3000000,
Wei.of(1000),
Wei.ZERO,
@ -394,7 +394,7 @@ public class DefaultPrivacyController implements PrivacyController {
@Override
public boolean isGroupAdditionTransaction(final PrivateTransaction privateTransaction) {
return privateTransaction.getTo().isPresent()
&& privateTransaction.getTo().get().equals(Address.PRIVACY_PROXY)
&& privateTransaction.getTo().get().equals(Address.ONCHAIN_PRIVACY_PROXY)
&& privateTransaction
.getPayload()
.toHexString()

@ -232,20 +232,22 @@ public class PrivateGroupRehydrationBlockProcessor {
if (lastRootHash.equals(EMPTY_ROOT_HASH)) {
// inject management
final DefaultEvmAccount managementPrecompile =
privateWorldStateUpdater.createAccount(Address.DEFAULT_PRIVACY_MANAGEMENT);
privateWorldStateUpdater.createAccount(Address.DEFAULT_ONCHAIN_PRIVACY_MANAGEMENT);
final MutableAccount mutableManagementPrecompiled = managementPrecompile.getMutable();
// this is the code for the simple management contract
mutableManagementPrecompiled.setCode(OnChainGroupManagement.DEFAULT_GROUP_MANAGEMENT_CODE);
mutableManagementPrecompiled.setCode(
OnChainGroupManagement.DEFAULT_GROUP_MANAGEMENT_RUNTIME_BYTECODE);
// inject proxy
final DefaultEvmAccount proxyPrecompile =
privateWorldStateUpdater.createAccount(Address.PRIVACY_PROXY);
privateWorldStateUpdater.createAccount(Address.ONCHAIN_PRIVACY_PROXY);
final MutableAccount mutableProxyPrecompiled = proxyPrecompile.getMutable();
// this is the code for the proxy contract
mutableProxyPrecompiled.setCode(OnChainGroupManagement.DEFAULT_PROXY_PRECOMPILED_CODE);
mutableProxyPrecompiled.setCode(OnChainGroupManagement.PROXY_RUNTIME_BYTECODE);
// manually set the management contract address so the proxy can trust it
mutableProxyPrecompiled.setStorageValue(
UInt256.ZERO, UInt256.fromBytes(Bytes32.leftPad(Address.DEFAULT_PRIVACY_MANAGEMENT)));
UInt256.ZERO,
UInt256.fromBytes(Bytes32.leftPad(Address.DEFAULT_ONCHAIN_PRIVACY_MANAGEMENT)));
privateWorldStateUpdater.commit();
disposablePrivateState.persist();

@ -26,7 +26,6 @@ import org.web3j.abi.datatypes.DynamicArray;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Bytes32;
import org.web3j.abi.datatypes.generated.Int256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.RemoteCall;
@ -45,10 +44,10 @@ import org.web3j.tx.gas.ContractGasProvider;
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the <a
* href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
*
* <p>Generated with web3j version 4.5.14.
* <p>Generated with web3j version 4.5.15.
*/
@SuppressWarnings("rawtypes")
public class PrivacyInterface extends Contract {
public class OnChainPrivacyGroupManagementInterface extends Contract {
public static final String BINARY = "";
public static final String FUNC_ADDPARTICIPANTS = "addParticipants";
@ -66,7 +65,7 @@ public class PrivacyInterface extends Contract {
public static final String FUNC_UNLOCK = "unlock";
@Deprecated
protected PrivacyInterface(
protected OnChainPrivacyGroupManagementInterface(
String contractAddress,
Web3j web3j,
Credentials credentials,
@ -75,7 +74,7 @@ public class PrivacyInterface extends Contract {
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
protected PrivacyInterface(
protected OnChainPrivacyGroupManagementInterface(
String contractAddress,
Web3j web3j,
Credentials credentials,
@ -84,7 +83,7 @@ public class PrivacyInterface extends Contract {
}
@Deprecated
protected PrivacyInterface(
protected OnChainPrivacyGroupManagementInterface(
String contractAddress,
Web3j web3j,
TransactionManager transactionManager,
@ -93,7 +92,7 @@ public class PrivacyInterface extends Contract {
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
protected PrivacyInterface(
protected OnChainPrivacyGroupManagementInterface(
String contractAddress,
Web3j web3j,
TransactionManager transactionManager,
@ -143,13 +142,13 @@ public class PrivacyInterface extends Contract {
});
}
public RemoteFunctionCall<BigInteger> getVersion() {
public RemoteFunctionCall<byte[]> getVersion() {
final Function function =
new Function(
FUNC_GETVERSION,
Arrays.<Type>asList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Int256>() {}));
return executeRemoteCallSingleValueReturn(function, BigInteger.class);
Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}));
return executeRemoteCallSingleValueReturn(function, byte[].class);
}
public RemoteFunctionCall<TransactionReceipt> lock() {
@ -177,67 +176,93 @@ public class PrivacyInterface extends Contract {
}
@Deprecated
public static PrivacyInterface load(
public static OnChainPrivacyGroupManagementInterface load(
String contractAddress,
Web3j web3j,
Credentials credentials,
BigInteger gasPrice,
BigInteger gasLimit) {
return new PrivacyInterface(contractAddress, web3j, credentials, gasPrice, gasLimit);
return new OnChainPrivacyGroupManagementInterface(
contractAddress, web3j, credentials, gasPrice, gasLimit);
}
@Deprecated
public static PrivacyInterface load(
public static OnChainPrivacyGroupManagementInterface load(
String contractAddress,
Web3j web3j,
TransactionManager transactionManager,
BigInteger gasPrice,
BigInteger gasLimit) {
return new PrivacyInterface(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
return new OnChainPrivacyGroupManagementInterface(
contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
public static PrivacyInterface load(
public static OnChainPrivacyGroupManagementInterface load(
String contractAddress,
Web3j web3j,
Credentials credentials,
ContractGasProvider contractGasProvider) {
return new PrivacyInterface(contractAddress, web3j, credentials, contractGasProvider);
return new OnChainPrivacyGroupManagementInterface(
contractAddress, web3j, credentials, contractGasProvider);
}
public static PrivacyInterface load(
public static OnChainPrivacyGroupManagementInterface load(
String contractAddress,
Web3j web3j,
TransactionManager transactionManager,
ContractGasProvider contractGasProvider) {
return new PrivacyInterface(contractAddress, web3j, transactionManager, contractGasProvider);
return new OnChainPrivacyGroupManagementInterface(
contractAddress, web3j, transactionManager, contractGasProvider);
}
public static RemoteCall<PrivacyInterface> deploy(
public static RemoteCall<OnChainPrivacyGroupManagementInterface> deploy(
Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return deployRemoteCall(
PrivacyInterface.class, web3j, credentials, contractGasProvider, BINARY, "");
OnChainPrivacyGroupManagementInterface.class,
web3j,
credentials,
contractGasProvider,
BINARY,
"");
}
@Deprecated
public static RemoteCall<PrivacyInterface> deploy(
public static RemoteCall<OnChainPrivacyGroupManagementInterface> deploy(
Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(
PrivacyInterface.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
OnChainPrivacyGroupManagementInterface.class,
web3j,
credentials,
gasPrice,
gasLimit,
BINARY,
"");
}
public static RemoteCall<PrivacyInterface> deploy(
public static RemoteCall<OnChainPrivacyGroupManagementInterface> deploy(
Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return deployRemoteCall(
PrivacyInterface.class, web3j, transactionManager, contractGasProvider, BINARY, "");
OnChainPrivacyGroupManagementInterface.class,
web3j,
transactionManager,
contractGasProvider,
BINARY,
"");
}
@Deprecated
public static RemoteCall<PrivacyInterface> deploy(
public static RemoteCall<OnChainPrivacyGroupManagementInterface> deploy(
Web3j web3j,
TransactionManager transactionManager,
BigInteger gasPrice,
BigInteger gasLimit) {
return deployRemoteCall(
PrivacyInterface.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
OnChainPrivacyGroupManagementInterface.class,
web3j,
transactionManager,
gasPrice,
gasLimit,
BINARY,
"");
}
}

@ -4,11 +4,11 @@ import "./OnChainPrivacyGroupManagementInterface.sol";
contract DefaultOnChainPrivacyGroupManagementContract is OnChainPrivacyGroupManagementInterface {
bool private _canExecute;
int private _version;
bytes32 private _version;
bytes32[] private distributionList;
mapping(bytes32 => uint256) private distributionIndexOf;
function getVersion() external view returns (int) {
function getVersion() external view returns (bytes32) {
return _version;
}
@ -35,13 +35,15 @@ contract DefaultOnChainPrivacyGroupManagementContract is OnChainPrivacyGroupMana
require(isMember(_enclaveKey));
bool result = addAll(_enclaveKey, _accounts);
_canExecute = true;
_version++;
updateVersion();
return result;
}
function removeParticipant(bytes32 _enclaveKey, bytes32 _account) public returns (bool) {
require(isMember(_enclaveKey));
return removeInternal(_account);
bool result = removeInternal(_account);
updateVersion();
return result;
}
function getParticipants(bytes32 _enclaveKey) public view returns (bytes32[] memory) {
@ -98,6 +100,10 @@ contract DefaultOnChainPrivacyGroupManagementContract is OnChainPrivacyGroupMana
return false;
}
function updateVersion() internal returns (int) {
_version = keccak256(abi.encodePacked(blockhash(block.number-1), block.coinbase, distributionList));
}
event ParticipantAdded(
bool adminAdded,
bytes32 account,

@ -14,5 +14,5 @@ interface OnChainPrivacyGroupManagementInterface {
function canExecute() external view returns (bool);
function getVersion() external view returns (int);
function getVersion() external view returns (bytes32);
}

@ -49,7 +49,7 @@ contract OnChainPrivacyGroupManagementProxy is OnChainPrivacyGroupManagementInte
return privacyInterface.canExecute();
}
function getVersion() public view returns (int) {
function getVersion() public view returns (bytes32) {
OnChainPrivacyGroupManagementInterface privacyInterface = OnChainPrivacyGroupManagementInterface(implementation);
return privacyInterface.getVersion();
}

@ -22,4 +22,5 @@ for target in ${targets}; do
-o ../java \
-p org.hyperledger.besu.privacy.contracts.generated
solc --bin-runtime --overwrite -o . ./${target}.sol
done
Loading…
Cancel
Save