Enclave key rename (#1442)

* rename transactionEnclaveKey -> privateTransactionLookupId

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/1410/head
Sally MacFarlane 4 years ago committed by GitHub
parent b2e3c42ece
commit fcb62e9554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 46
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/multitenancy/MultiTenancyAcceptanceTest.java
  2. 22
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java
  3. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java
  4. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyController.java
  5. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/MultiTenancyPrivacyController.java
  6. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java
  7. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactory.java
  8. 14
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/PrivateMarkerTransactionFactory.java
  9. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactory.java
  10. 22
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContractTest.java
  11. 26
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractTest.java
  12. 16
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyControllerTest.java
  13. 8
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionLocatorTest.java

@ -63,10 +63,14 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
new BigInteger( new BigInteger(
"853d7f0010fd86d0d7811c1f9d968ea89a24484a8127b4a483ddf5d2cfec766d", 16))); "853d7f0010fd86d0d7811c1f9d968ea89a24484a8127b4a483ddf5d2cfec766d", 16)));
private static final String PRIVACY_GROUP_ID = "B1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; private static final String PRIVACY_GROUP_ID = "B1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=";
private static final String ENCLAVE_KEY = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; private static final String PARTICIPANT_ENCLAVE_KEY0 =
private static final String KEY1 = "sgFkVOyFndZe/5SAZJO5UYbrl7pezHetveriBBWWnE8="; "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=";
private static final String KEY2 = "R1kW75NQC9XX3kwNpyPjCBFflM29+XvnKKS9VLrUkzo="; private static final String PARTICIPANT_ENCLAVE_KEY1 =
private static final String KEY3 = "QzHuACXpfhoGAgrQriWJcDJ6MrUwcCvutKMoAn9KplQ="; "sgFkVOyFndZe/5SAZJO5UYbrl7pezHetveriBBWWnE8=";
private static final String PARTICIPANT_ENCLAVE_KEY2 =
"R1kW75NQC9XX3kwNpyPjCBFflM29+XvnKKS9VLrUkzo=";
private static final String PARTICIPANT_ENCLAVE_KEY3 =
"QzHuACXpfhoGAgrQriWJcDJ6MrUwcCvutKMoAn9KplQ=";
private final Address senderAddress = private final Address senderAddress =
Address.wrap(Bytes.fromHexString(accounts.getPrimaryBenefactor().getAddress())); Address.wrap(Bytes.fromHexString(accounts.getPrimaryBenefactor().getAddress()));
@ -108,7 +112,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
receiveEnclaveStub(validSignedPrivateTransaction); receiveEnclaveStub(validSignedPrivateTransaction);
retrievePrivacyGroupEnclaveStub(); retrievePrivacyGroupEnclaveStub();
sendEnclaveStub(KEY1); sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1);
final Hash transactionHash = final Hash transactionHash =
node.execute( node.execute(
@ -124,7 +128,10 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
node.verify( node.verify(
priv.createPrivacyGroup( priv.createPrivacyGroup(
List.of(KEY1, KEY2, KEY3), "GroupName", "Group description.", PRIVACY_GROUP_ID)); List.of(PARTICIPANT_ENCLAVE_KEY1, PARTICIPANT_ENCLAVE_KEY2, PARTICIPANT_ENCLAVE_KEY3),
"GroupName",
"Group description.",
PRIVACY_GROUP_ID));
} }
@Test @Test
@ -140,13 +147,13 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
throws JsonProcessingException { throws JsonProcessingException {
final List<PrivacyGroup> groupMembership = final List<PrivacyGroup> groupMembership =
List.of( List.of(
testPrivacyGroup(singletonList(ENCLAVE_KEY), PrivacyGroup.Type.PANTHEON), testPrivacyGroup(singletonList(PARTICIPANT_ENCLAVE_KEY0), PrivacyGroup.Type.PANTHEON),
testPrivacyGroup(singletonList(ENCLAVE_KEY), PrivacyGroup.Type.PANTHEON), testPrivacyGroup(singletonList(PARTICIPANT_ENCLAVE_KEY0), PrivacyGroup.Type.PANTHEON),
testPrivacyGroup(singletonList(ENCLAVE_KEY), PrivacyGroup.Type.PANTHEON)); testPrivacyGroup(singletonList(PARTICIPANT_ENCLAVE_KEY0), PrivacyGroup.Type.PANTHEON));
findPrivacyGroupEnclaveStub(groupMembership); findPrivacyGroupEnclaveStub(groupMembership);
node.verify(priv.findPrivacyGroup(groupMembership.size(), ENCLAVE_KEY)); node.verify(priv.findPrivacyGroup(groupMembership.size(), PARTICIPANT_ENCLAVE_KEY0));
} }
@Test @Test
@ -156,7 +163,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
getValidSignedPrivateTransaction(senderAddress); getValidSignedPrivateTransaction(senderAddress);
retrievePrivacyGroupEnclaveStub(); retrievePrivacyGroupEnclaveStub();
sendEnclaveStub(KEY1); sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1);
receiveEnclaveStub(validSignedPrivateTransaction); receiveEnclaveStub(validSignedPrivateTransaction);
node.verify( node.verify(
@ -173,7 +180,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
final BytesValueRLPOutput rlpOutput = getRLPOutput(validSignedPrivateTransaction); final BytesValueRLPOutput rlpOutput = getRLPOutput(validSignedPrivateTransaction);
retrievePrivacyGroupEnclaveStub(); retrievePrivacyGroupEnclaveStub();
sendEnclaveStub(KEY1); sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1);
receiveEnclaveStub(validSignedPrivateTransaction); receiveEnclaveStub(validSignedPrivateTransaction);
node.verify(priv.getTransactionCount(accountAddress, PRIVACY_GROUP_ID, 0)); node.verify(priv.getTransactionCount(accountAddress, PRIVACY_GROUP_ID, 0));
@ -187,10 +194,11 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
@Test @Test
public void privDistributeRawTransactionSuccessShouldReturnEnclaveKey() public void privDistributeRawTransactionSuccessShouldReturnEnclaveKey()
throws JsonProcessingException { throws JsonProcessingException {
final String enclaveResponseKeyBytes = Bytes.wrap(Bytes.fromBase64String(KEY1)).toString(); final String enclaveResponseKeyBytes =
Bytes.wrap(Bytes.fromBase64String(PARTICIPANT_ENCLAVE_KEY1)).toString();
retrievePrivacyGroupEnclaveStub(); retrievePrivacyGroupEnclaveStub();
sendEnclaveStub(KEY1); sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1);
node.verify( node.verify(
priv.distributeRawTransaction( priv.distributeRawTransaction(
@ -206,7 +214,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
final BytesValueRLPOutput rlpOutput = getRLPOutput(validSignedPrivateTransaction); final BytesValueRLPOutput rlpOutput = getRLPOutput(validSignedPrivateTransaction);
retrievePrivacyGroupEnclaveStub(); retrievePrivacyGroupEnclaveStub();
sendEnclaveStub(KEY1); sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1);
receiveEnclaveStub(validSignedPrivateTransaction); receiveEnclaveStub(validSignedPrivateTransaction);
final Hash transactionReceipt = final Hash transactionReceipt =
@ -227,7 +235,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
List.of(testPrivacyGroup(emptyList(), PrivacyGroup.Type.LEGACY)); List.of(testPrivacyGroup(emptyList(), PrivacyGroup.Type.LEGACY));
retrievePrivacyGroupEnclaveStub(); retrievePrivacyGroupEnclaveStub();
sendEnclaveStub(KEY1); sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1);
receiveEnclaveStub(validSignedPrivateTransaction); receiveEnclaveStub(validSignedPrivateTransaction);
findPrivacyGroupEnclaveStub(groupMembership); findPrivacyGroupEnclaveStub(groupMembership);
@ -237,7 +245,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
node.verify(priv.getSuccessfulTransactionReceipt(transactionHash)); node.verify(priv.getSuccessfulTransactionReceipt(transactionHash));
final String privateFrom = ENCLAVE_KEY; final String privateFrom = PARTICIPANT_ENCLAVE_KEY0;
final String[] privateFor = {senderAddressBase64}; final String[] privateFor = {senderAddressBase64};
node.verify(priv.getEeaTransactionCount(accountAddress, privateFrom, privateFor, 1)); node.verify(priv.getEeaTransactionCount(accountAddress, privateFrom, privateFor, 1));
} }
@ -262,7 +270,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
private void retrievePrivacyGroupEnclaveStub() throws JsonProcessingException { private void retrievePrivacyGroupEnclaveStub() throws JsonProcessingException {
final String retrieveGroupResponse = final String retrieveGroupResponse =
mapper.writeValueAsString( mapper.writeValueAsString(
testPrivacyGroup(List.of(ENCLAVE_KEY), PrivacyGroup.Type.PANTHEON)); testPrivacyGroup(List.of(PARTICIPANT_ENCLAVE_KEY0), PrivacyGroup.Type.PANTHEON));
stubFor(post("/retrievePrivacyGroup").willReturn(ok(retrieveGroupResponse))); stubFor(post("/retrievePrivacyGroup").willReturn(ok(retrieveGroupResponse)));
} }
@ -309,7 +317,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
.payload(Bytes.wrap(new byte[] {})) .payload(Bytes.wrap(new byte[] {}))
.sender(senderAddress) .sender(senderAddress)
.chainId(BigInteger.valueOf(2018)) .chainId(BigInteger.valueOf(2018))
.privateFrom(Bytes.fromBase64String(ENCLAVE_KEY)) .privateFrom(Bytes.fromBase64String(PARTICIPANT_ENCLAVE_KEY0))
.restriction(Restriction.RESTRICTED) .restriction(Restriction.RESTRICTED)
.privacyGroupId(Bytes.fromBase64String(PRIVACY_GROUP_ID)) .privacyGroupId(Bytes.fromBase64String(PRIVACY_GROUP_ID))
.signAndBuild(TEST_KEY); .signAndBuild(TEST_KEY);

@ -115,7 +115,7 @@ public class EeaSendRawTransaction implements JsonRpcMethod {
id, convertTransactionInvalidReason(validationResult.getInvalidReason())); id, convertTransactionInvalidReason(validationResult.getInvalidReason()));
} }
final String enclaveKey = final String privateTransactionLookupId =
privacyController.sendTransaction( privacyController.sendTransaction(
privateTransaction, enclavePublicKey, maybePrivacyGroup); privateTransaction, enclavePublicKey, maybePrivacyGroup);
@ -125,7 +125,7 @@ public class EeaSendRawTransaction implements JsonRpcMethod {
() -> () ->
new RuntimeException( new RuntimeException(
JsonRpcError.OFFCHAIN_PRIVACY_GROUP_DOES_NOT_EXIST.getMessage())); JsonRpcError.OFFCHAIN_PRIVACY_GROUP_DOES_NOT_EXIST.getMessage()));
final Optional<String> addPayloadEnclaveKey = final Optional<String> addPayloadPrivateTransactionLookupId =
privacyController.buildAndSendAddPayload( privacyController.buildAndSendAddPayload(
privateTransaction, privateTransaction,
Bytes32.wrap(privacyGroupId), Bytes32.wrap(privacyGroupId),
@ -133,10 +133,11 @@ public class EeaSendRawTransaction implements JsonRpcMethod {
return createPMTAndAddToTxPool( return createPMTAndAddToTxPool(
id, id,
privateTransaction, privateTransaction,
buildCompoundKey(enclaveKey, addPayloadEnclaveKey), buildCompoundLookupId(privateTransactionLookupId, addPayloadPrivateTransactionLookupId),
Address.ONCHAIN_PRIVACY); Address.ONCHAIN_PRIVACY);
} else { // legacy or pantheon transaction } else { // legacy or pantheon transaction
return createPMTAndAddToTxPool(id, privateTransaction, enclaveKey, Address.DEFAULT_PRIVACY); return createPMTAndAddToTxPool(
id, privateTransaction, privateTransactionLookupId, Address.DEFAULT_PRIVACY);
} }
} catch (final IllegalArgumentException | RLPException e) { } catch (final IllegalArgumentException | RLPException e) {
return new JsonRpcErrorResponse(id, DECODE_ERROR); return new JsonRpcErrorResponse(id, DECODE_ERROR);
@ -170,13 +171,14 @@ public class EeaSendRawTransaction implements JsonRpcMethod {
return new JsonRpcErrorResponse(id, convertTransactionInvalidReason(errorReason)); return new JsonRpcErrorResponse(id, convertTransactionInvalidReason(errorReason));
} }
private String buildCompoundKey( private String buildCompoundLookupId(
final String enclaveKey, final Optional<String> addPayloadEnclaveKey) { final String privateTransactionLookupId,
return addPayloadEnclaveKey.isPresent() final Optional<String> maybePrivateTransactionLookupId) {
return maybePrivateTransactionLookupId.isPresent()
? Bytes.concatenate( ? Bytes.concatenate(
Bytes.fromBase64String(enclaveKey), Bytes.fromBase64String(privateTransactionLookupId),
Bytes.fromBase64String(addPayloadEnclaveKey.get())) Bytes.fromBase64String(maybePrivateTransactionLookupId.get()))
.toBase64String() .toBase64String()
: enclaveKey; : privateTransactionLookupId;
} }
} }

@ -37,7 +37,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorR
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Wei; import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
@ -58,7 +57,6 @@ import io.vertx.core.json.JsonObject;
import io.vertx.ext.auth.User; import io.vertx.ext.auth.User;
import io.vertx.ext.auth.jwt.impl.JWTUser; import io.vertx.ext.auth.jwt.impl.JWTUser;
import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -108,7 +106,6 @@ public class EeaSendRawTransactionTest {
@Mock private TransactionPool transactionPool; @Mock private TransactionPool transactionPool;
@Mock private EeaSendRawTransaction method; @Mock private EeaSendRawTransaction method;
@Mock private PrivacyController privacyController; @Mock private PrivacyController privacyController;
@Mock private PrivacyParameters privacyParameters;
@Before @Before
public void before() { public void before() {
@ -255,9 +252,6 @@ public class EeaSendRawTransactionTest {
"", PrivacyGroup.Type.ONCHAIN, "", "", Arrays.asList(ENCLAVE_PUBLIC_KEY))); "", PrivacyGroup.Type.ONCHAIN, "", "", Arrays.asList(ENCLAVE_PUBLIC_KEY)));
when(privacyController.retrieveOnChainPrivacyGroupWithToBeAddedMembers(any(), any(), any())) when(privacyController.retrieveOnChainPrivacyGroupWithToBeAddedMembers(any(), any(), any()))
.thenReturn(optionalPrivacyGroup); .thenReturn(optionalPrivacyGroup);
when(privacyController.buildAndSendAddPayload(
any(PrivateTransaction.class), any(Bytes32.class), any(String.class)))
.thenReturn(Optional.of(ENCLAVE_PUBLIC_KEY));
when(privacyController.createPrivacyMarkerTransaction( when(privacyController.createPrivacyMarkerTransaction(
any(String.class), any(PrivateTransaction.class), any(Address.class))) any(String.class), any(PrivateTransaction.class), any(Address.class)))
.thenReturn(PUBLIC_TRANSACTION); .thenReturn(PUBLIC_TRANSACTION);

@ -164,17 +164,17 @@ public class DefaultPrivacyController implements PrivacyController {
@Override @Override
public Transaction createPrivacyMarkerTransaction( public Transaction createPrivacyMarkerTransaction(
final String transactionEnclaveKey, final PrivateTransaction privateTransaction) { final String privateTransactionLookupId, final PrivateTransaction privateTransaction) {
return privateMarkerTransactionFactory.create(transactionEnclaveKey, privateTransaction); return privateMarkerTransactionFactory.create(privateTransactionLookupId, privateTransaction);
} }
@Override @Override
public Transaction createPrivacyMarkerTransaction( public Transaction createPrivacyMarkerTransaction(
final String transactionEnclaveKey, final String privateTransactionLookupId,
final PrivateTransaction privateTransaction, final PrivateTransaction privateTransaction,
final Address privacyPrecompileAddress) { final Address privacyPrecompileAddress) {
return privateMarkerTransactionFactory.create( return privateMarkerTransactionFactory.create(
transactionEnclaveKey, privateTransaction, privacyPrecompileAddress); privateTransactionLookupId, privateTransaction, privacyPrecompileAddress);
} }
@Override @Override

@ -129,18 +129,18 @@ public class MultiTenancyPrivacyController implements PrivacyController {
@Override @Override
public Transaction createPrivacyMarkerTransaction( public Transaction createPrivacyMarkerTransaction(
final String transactionEnclaveKey, final PrivateTransaction privateTransaction) { final String privateTransactionLookupId, final PrivateTransaction privateTransaction) {
return privacyController.createPrivacyMarkerTransaction( return privacyController.createPrivacyMarkerTransaction(
transactionEnclaveKey, privateTransaction); privateTransactionLookupId, privateTransaction);
} }
@Override @Override
public Transaction createPrivacyMarkerTransaction( public Transaction createPrivacyMarkerTransaction(
final String transactionEnclaveKey, final String privateTransactionLookupId,
final PrivateTransaction privateTransaction, final PrivateTransaction privateTransaction,
final Address privacyPrecompileAddress) { final Address privacyPrecompileAddress) {
return privacyController.createPrivacyMarkerTransaction( return privacyController.createPrivacyMarkerTransaction(
transactionEnclaveKey, privateTransaction, privacyPrecompileAddress); privateTransactionLookupId, privateTransaction, privacyPrecompileAddress);
} }
@Override @Override

@ -49,10 +49,10 @@ public interface PrivacyController {
PrivacyGroup[] findPrivacyGroup(List<String> addresses, String enclavePublicKey); PrivacyGroup[] findPrivacyGroup(List<String> addresses, String enclavePublicKey);
Transaction createPrivacyMarkerTransaction( Transaction createPrivacyMarkerTransaction(
String transactionEnclaveKey, PrivateTransaction privateTransaction); String privateTransactionLookupId, PrivateTransaction privateTransaction);
Transaction createPrivacyMarkerTransaction( Transaction createPrivacyMarkerTransaction(
String transactionEnclaveKey, String privateTransactionLookupId,
PrivateTransaction privateTransaction, PrivateTransaction privateTransaction,
Address privacyPrecompileAddress); Address privacyPrecompileAddress);

@ -40,11 +40,11 @@ public class FixedKeySigningPrivateMarkerTransactionFactory
@Override @Override
public Transaction create( public Transaction create(
final String transactionEnclaveKey, final String privateTransactionLookupId,
final PrivateTransaction privateTransaction, final PrivateTransaction privateTransaction,
final Address precompileAddress) { final Address precompileAddress) {
return create( return create(
transactionEnclaveKey, privateTransactionLookupId,
privateTransaction, privateTransaction,
nonceProvider.getNonce(sender), nonceProvider.getNonce(sender),
signingKey, signingKey,

@ -34,17 +34,17 @@ public abstract class PrivateMarkerTransactionFactory {
} }
public Transaction create( public Transaction create(
final String transactionEnclaveKey, final PrivateTransaction privateTransaction) { final String privateTransactionLookupId, final PrivateTransaction privateTransaction) {
return create(transactionEnclaveKey, privateTransaction, privacyPrecompileAddress); return create(privateTransactionLookupId, privateTransaction, privacyPrecompileAddress);
} }
public abstract Transaction create( public abstract Transaction create(
final String transactionEnclaveKey, final String privateTransactionLookupId,
final PrivateTransaction privateTransaction, final PrivateTransaction privateTransaction,
final Address precompileAddress); final Address precompileAddress);
protected Transaction create( protected Transaction create(
final String transactionEnclaveKey, final String privateTransactionLookupId,
final PrivateTransaction privateTransaction, final PrivateTransaction privateTransaction,
final long nonce, final long nonce,
final KeyPair signingKey) { final KeyPair signingKey) {
@ -54,12 +54,12 @@ public abstract class PrivateMarkerTransactionFactory {
.gasLimit(privateTransaction.getGasLimit()) .gasLimit(privateTransaction.getGasLimit())
.to(getPrivacyPrecompileAddress()) .to(getPrivacyPrecompileAddress())
.value(privateTransaction.getValue()) .value(privateTransaction.getValue())
.payload(Bytes.fromBase64String(transactionEnclaveKey)) .payload(Bytes.fromBase64String(privateTransactionLookupId))
.signAndBuild(signingKey); .signAndBuild(signingKey);
} }
protected Transaction create( protected Transaction create(
final String transactionEnclaveKey, final String privateTransactionLookupId,
final PrivateTransaction privateTransaction, final PrivateTransaction privateTransaction,
final long nonce, final long nonce,
final KeyPair signingKey, final KeyPair signingKey,
@ -70,7 +70,7 @@ public abstract class PrivateMarkerTransactionFactory {
.gasLimit(privateTransaction.getGasLimit()) .gasLimit(privateTransaction.getGasLimit())
.to(precompileAddress) .to(precompileAddress)
.value(privateTransaction.getValue()) .value(privateTransaction.getValue())
.payload(Bytes.fromBase64String(transactionEnclaveKey)) .payload(Bytes.fromBase64String(privateTransactionLookupId))
.signAndBuild(signingKey); .signAndBuild(signingKey);
} }
} }

@ -27,10 +27,10 @@ public class RandomSigningPrivateMarkerTransactionFactory extends PrivateMarkerT
@Override @Override
public Transaction create( public Transaction create(
final String transactionEnclaveKey, final String privateTransactionLookupId,
final PrivateTransaction privateTransaction, final PrivateTransaction privateTransaction,
final Address precompileAddress) { final Address precompileAddress) {
final KeyPair signingKey = KeyPair.generate(); final KeyPair signingKey = KeyPair.generate();
return create(transactionEnclaveKey, privateTransaction, 0, signingKey, precompileAddress); return create(privateTransactionLookupId, privateTransaction, 0, signingKey, precompileAddress);
} }
} }

@ -71,7 +71,7 @@ public class OnChainPrivacyPrecompiledContractTest {
@Rule public final TemporaryFolder temp = new TemporaryFolder(); @Rule public final TemporaryFolder temp = new TemporaryFolder();
private final Bytes txEnclaveKey = Bytes.random(32); private final Bytes privateTransactionLookupId = Bytes.random(32);
private MessageFrame messageFrame; private MessageFrame messageFrame;
private Blockchain blockchain; private Blockchain blockchain;
private final String DEFAULT_OUTPUT = "0x01"; private final String DEFAULT_OUTPUT = "0x01";
@ -166,7 +166,7 @@ public class OnChainPrivacyPrecompiledContractTest {
.when(contractSpy) .when(contractSpy)
.canExecute(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); .canExecute(any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
final Bytes actual = contractSpy.compute(txEnclaveKey, messageFrame); final Bytes actual = contractSpy.compute(privateTransactionLookupId, messageFrame);
assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT)); assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
} }
@ -178,7 +178,7 @@ public class OnChainPrivacyPrecompiledContractTest {
when(enclave.receive(any(String.class))).thenThrow(EnclaveClientException.class); when(enclave.receive(any(String.class))).thenThrow(EnclaveClientException.class);
final Bytes expected = contract.compute(txEnclaveKey, messageFrame); final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame);
assertThat(expected).isEqualTo(Bytes.EMPTY); assertThat(expected).isEqualTo(Bytes.EMPTY);
} }
@ -189,7 +189,7 @@ public class OnChainPrivacyPrecompiledContractTest {
when(enclave.receive(any(String.class))).thenThrow(new RuntimeException()); when(enclave.receive(any(String.class))).thenThrow(new RuntimeException());
contract.compute(txEnclaveKey, messageFrame); contract.compute(privateTransactionLookupId, messageFrame);
} }
@Test @Test
@ -202,9 +202,10 @@ public class OnChainPrivacyPrecompiledContractTest {
final ReceiveResponse responseWithoutSenderKey = final ReceiveResponse responseWithoutSenderKey =
new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, null); new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, null);
when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(responseWithoutSenderKey); when(enclave.receive(eq(privateTransactionLookupId.toBase64String())))
.thenReturn(responseWithoutSenderKey);
assertThatThrownBy(() -> contract.compute(txEnclaveKey, messageFrame)) assertThatThrownBy(() -> contract.compute(privateTransactionLookupId, messageFrame))
.isInstanceOf(EnclaveConfigurationException.class) .isInstanceOf(EnclaveConfigurationException.class)
.hasMessage("Incompatible Orion version. Orion version must be 1.6.0 or greater."); .hasMessage("Incompatible Orion version. Orion version must be 1.6.0 or greater.");
} }
@ -220,9 +221,10 @@ public class OnChainPrivacyPrecompiledContractTest {
final String wrongSenderKey = Bytes.random(32).toBase64String(); final String wrongSenderKey = Bytes.random(32).toBase64String();
final ReceiveResponse responseWithWrongSenderKey = final ReceiveResponse responseWithWrongSenderKey =
new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, wrongSenderKey); new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, wrongSenderKey);
when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(responseWithWrongSenderKey); when(enclave.receive(eq(privateTransactionLookupId.toBase64String())))
.thenReturn(responseWithWrongSenderKey);
final Bytes expected = contract.compute(txEnclaveKey, messageFrame); final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame);
assertThat(expected).isEqualTo(Bytes.EMPTY); assertThat(expected).isEqualTo(Bytes.EMPTY);
} }
@ -256,7 +258,7 @@ public class OnChainPrivacyPrecompiledContractTest {
new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom); new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
when(enclave.receive(any(String.class))).thenReturn(response); when(enclave.receive(any(String.class))).thenReturn(response);
final Bytes actual = contractSpy.compute(txEnclaveKey, messageFrame); final Bytes actual = contractSpy.compute(privateTransactionLookupId, messageFrame);
assertThat(actual).isEqualTo(Bytes.EMPTY); assertThat(actual).isEqualTo(Bytes.EMPTY);
} }
@ -294,7 +296,7 @@ public class OnChainPrivacyPrecompiledContractTest {
when(enclave.receive(any(String.class))).thenReturn(response); when(enclave.receive(any(String.class))).thenReturn(response);
final Bytes actual = contractSpy.compute(txEnclaveKey, messageFrame); final Bytes actual = contractSpy.compute(privateTransactionLookupId, messageFrame);
assertThat(actual).isEqualTo(Bytes.EMPTY); assertThat(actual).isEqualTo(Bytes.EMPTY);
} }

@ -73,7 +73,7 @@ public class PrivacyPrecompiledContractTest {
@Rule public final TemporaryFolder temp = new TemporaryFolder(); @Rule public final TemporaryFolder temp = new TemporaryFolder();
private final String actual = "Test String"; private final String actual = "Test String";
private final Bytes txEnclaveKey = Bytes.wrap(actual.getBytes(UTF_8)); private final Bytes privateTransactionLookupId = Bytes.wrap(actual.getBytes(UTF_8));
private MessageFrame messageFrame; private MessageFrame messageFrame;
private Blockchain blockchain; private Blockchain blockchain;
private final String DEFAULT_OUTPUT = "0x01"; private final String DEFAULT_OUTPUT = "0x01";
@ -160,7 +160,7 @@ public class PrivacyPrecompiledContractTest {
new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom); new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
when(enclave.receive(any(String.class))).thenReturn(response); when(enclave.receive(any(String.class))).thenReturn(response);
final Bytes actual = contract.compute(txEnclaveKey, messageFrame); final Bytes actual = contract.compute(privateTransactionLookupId, messageFrame);
assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT)); assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
} }
@ -172,7 +172,7 @@ public class PrivacyPrecompiledContractTest {
when(enclave.receive(any(String.class))).thenThrow(EnclaveClientException.class); when(enclave.receive(any(String.class))).thenThrow(EnclaveClientException.class);
final Bytes expected = contract.compute(txEnclaveKey, messageFrame); final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame);
assertThat(expected).isEqualTo(Bytes.EMPTY); assertThat(expected).isEqualTo(Bytes.EMPTY);
} }
@ -183,7 +183,7 @@ public class PrivacyPrecompiledContractTest {
when(enclave.receive(any(String.class))).thenThrow(new RuntimeException()); when(enclave.receive(any(String.class))).thenThrow(new RuntimeException());
contract.compute(txEnclaveKey, messageFrame); contract.compute(privateTransactionLookupId, messageFrame);
} }
@Test @Test
@ -195,9 +195,10 @@ public class PrivacyPrecompiledContractTest {
final ReceiveResponse responseWithoutSenderKey = final ReceiveResponse responseWithoutSenderKey =
new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, null); new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, null);
when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(responseWithoutSenderKey); when(enclave.receive(eq(privateTransactionLookupId.toBase64String())))
.thenReturn(responseWithoutSenderKey);
assertThatThrownBy(() -> contract.compute(txEnclaveKey, messageFrame)) assertThatThrownBy(() -> contract.compute(privateTransactionLookupId, messageFrame))
.isInstanceOf(EnclaveConfigurationException.class) .isInstanceOf(EnclaveConfigurationException.class)
.hasMessage("Incompatible Orion version. Orion version must be 1.6.0 or greater."); .hasMessage("Incompatible Orion version. Orion version must be 1.6.0 or greater.");
} }
@ -213,9 +214,9 @@ public class PrivacyPrecompiledContractTest {
final String senderKey = privateTransaction.getPrivateFrom().toBase64String(); final String senderKey = privateTransaction.getPrivateFrom().toBase64String();
final ReceiveResponse response = final ReceiveResponse response =
new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, senderKey); new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, senderKey);
when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(response); when(enclave.receive(eq(privateTransactionLookupId.toBase64String()))).thenReturn(response);
final Bytes expected = contract.compute(txEnclaveKey, messageFrame); final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame);
assertThat(expected).isEqualTo(Bytes.EMPTY); assertThat(expected).isEqualTo(Bytes.EMPTY);
} }
@ -229,9 +230,10 @@ public class PrivacyPrecompiledContractTest {
final String wrongSenderKey = Bytes.random(32).toBase64String(); final String wrongSenderKey = Bytes.random(32).toBase64String();
final ReceiveResponse responseWithWrongSenderKey = final ReceiveResponse responseWithWrongSenderKey =
new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, wrongSenderKey); new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, wrongSenderKey);
when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(responseWithWrongSenderKey); when(enclave.receive(eq(privateTransactionLookupId.toBase64String())))
.thenReturn(responseWithWrongSenderKey);
final Bytes expected = contract.compute(txEnclaveKey, messageFrame); final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame);
assertThat(expected).isEqualTo(Bytes.EMPTY); assertThat(expected).isEqualTo(Bytes.EMPTY);
} }
@ -260,7 +262,7 @@ public class PrivacyPrecompiledContractTest {
new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom); new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
when(enclave.receive(any(String.class))).thenReturn(response); when(enclave.receive(any(String.class))).thenReturn(response);
final Bytes actual = contract.compute(txEnclaveKey, messageFrame); final Bytes actual = contract.compute(privateTransactionLookupId, messageFrame);
assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT)); assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
} }
@ -298,7 +300,7 @@ public class PrivacyPrecompiledContractTest {
when(enclave.receive(any(String.class))).thenReturn(response); when(enclave.receive(any(String.class))).thenReturn(response);
final Bytes actual = contract.compute(txEnclaveKey, messageFrame); final Bytes actual = contract.compute(privateTransactionLookupId, messageFrame);
assertThat(actual).isEqualTo(Bytes.EMPTY); assertThat(actual).isEqualTo(Bytes.EMPTY);
} }

@ -89,7 +89,7 @@ public class DefaultPrivacyControllerTest {
"0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002"; "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002";
private static final PrivacyGroup PANTHEON_PRIVACY_GROUP = private static final PrivacyGroup PANTHEON_PRIVACY_GROUP =
new PrivacyGroup("", PrivacyGroup.Type.PANTHEON, "", "", emptyList()); new PrivacyGroup("", PrivacyGroup.Type.PANTHEON, "", "", emptyList());
private static final PrivacyGroup ON_CHAIN_PRIVACY_GROUP = private static final PrivacyGroup ONCHAIN_PRIVACY_GROUP =
new PrivacyGroup("", PrivacyGroup.Type.ONCHAIN, "", "", Arrays.asList(ENCLAVE_PUBLIC_KEY)); new PrivacyGroup("", PrivacyGroup.Type.ONCHAIN, "", "", Arrays.asList(ENCLAVE_PUBLIC_KEY));
private PrivacyController privacyController; private PrivacyController privacyController;
@ -185,14 +185,14 @@ public class DefaultPrivacyControllerTest {
public void sendsValidLegacyTransaction() { public void sendsValidLegacyTransaction() {
final PrivateTransaction transaction = buildLegacyPrivateTransaction(1); final PrivateTransaction transaction = buildLegacyPrivateTransaction(1);
final String enclaveKey = final String privateTransactionLookupId =
privacyController.sendTransaction(transaction, ENCLAVE_PUBLIC_KEY, Optional.empty()); privacyController.sendTransaction(transaction, ENCLAVE_PUBLIC_KEY, Optional.empty());
final ValidationResult<TransactionInvalidReason> validationResult = final ValidationResult<TransactionInvalidReason> validationResult =
privacyController.validatePrivateTransaction(transaction, ENCLAVE_PUBLIC_KEY); privacyController.validatePrivateTransaction(transaction, ENCLAVE_PUBLIC_KEY);
final Transaction markerTransaction = final Transaction markerTransaction =
privacyController.createPrivacyMarkerTransaction(enclaveKey, transaction); privacyController.createPrivacyMarkerTransaction(privateTransactionLookupId, transaction);
assertThat(validationResult).isEqualTo(ValidationResult.valid()); assertThat(validationResult).isEqualTo(ValidationResult.valid());
assertThat(markerTransaction.contractAddress()).isEqualTo(PUBLIC_TRANSACTION.contractAddress()); assertThat(markerTransaction.contractAddress()).isEqualTo(PUBLIC_TRANSACTION.contractAddress());
@ -208,7 +208,7 @@ public class DefaultPrivacyControllerTest {
public void sendValidBesuTransaction() { public void sendValidBesuTransaction() {
final PrivateTransaction transaction = buildBesuPrivateTransaction(1); final PrivateTransaction transaction = buildBesuPrivateTransaction(1);
final String enclaveKey = final String privateTransactionLookupId =
privacyController.sendTransaction( privacyController.sendTransaction(
transaction, ENCLAVE_PUBLIC_KEY, Optional.of(PANTHEON_PRIVACY_GROUP)); transaction, ENCLAVE_PUBLIC_KEY, Optional.of(PANTHEON_PRIVACY_GROUP));
@ -216,7 +216,7 @@ public class DefaultPrivacyControllerTest {
privacyController.validatePrivateTransaction(transaction, ENCLAVE_PUBLIC_KEY); privacyController.validatePrivateTransaction(transaction, ENCLAVE_PUBLIC_KEY);
final Transaction markerTransaction = final Transaction markerTransaction =
privacyController.createPrivacyMarkerTransaction(enclaveKey, transaction); privacyController.createPrivacyMarkerTransaction(privateTransactionLookupId, transaction);
assertThat(validationResult).isEqualTo(ValidationResult.valid()); assertThat(validationResult).isEqualTo(ValidationResult.valid());
assertThat(markerTransaction.contractAddress()).isEqualTo(PUBLIC_TRANSACTION.contractAddress()); assertThat(markerTransaction.contractAddress()).isEqualTo(PUBLIC_TRANSACTION.contractAddress());
@ -449,13 +449,13 @@ public class DefaultPrivacyControllerTest {
public void canCreatePrivacyMarkerTransactionForOnChainPrivacy() { public void canCreatePrivacyMarkerTransactionForOnChainPrivacy() {
final PrivateTransaction transaction = buildBesuPrivateTransaction(0); final PrivateTransaction transaction = buildBesuPrivateTransaction(0);
final String enclaveKey = final String privateTransactionLookupId =
privacyController.sendTransaction( privacyController.sendTransaction(
transaction, ENCLAVE_PUBLIC_KEY, Optional.of(ON_CHAIN_PRIVACY_GROUP)); transaction, ENCLAVE_PUBLIC_KEY, Optional.of(ONCHAIN_PRIVACY_GROUP));
final Transaction onChainPrivacyMarkerTransaction = final Transaction onChainPrivacyMarkerTransaction =
privacyController.createPrivacyMarkerTransaction( privacyController.createPrivacyMarkerTransaction(
enclaveKey, transaction, Address.ONCHAIN_PRIVACY); privateTransactionLookupId, transaction, Address.ONCHAIN_PRIVACY);
assertThat(onChainPrivacyMarkerTransaction.contractAddress()) assertThat(onChainPrivacyMarkerTransaction.contractAddress())
.isEqualTo(PUBLIC_TRANSACTION.contractAddress()); .isEqualTo(PUBLIC_TRANSACTION.contractAddress());

@ -243,12 +243,12 @@ public class PrivateTransactionLocatorTest {
final Transaction pmt, final Transaction pmt,
final PrivateTransaction privateTransaction, final PrivateTransaction privateTransaction,
final Optional<Bytes32> version) { final Optional<Bytes32> version) {
final String privateTxEnclaveKey = pmt.getData().orElseThrow().toBase64String(); final String privateTransactionLookupId = pmt.getData().orElseThrow().toBase64String();
final byte[] encodePrivateTransaction = final byte[] encodePrivateTransaction =
encodePrivateTransaction(privateTransaction, version) encodePrivateTransaction(privateTransaction, version)
.toBase64String() .toBase64String()
.getBytes(StandardCharsets.UTF_8); .getBytes(StandardCharsets.UTF_8);
when(enclave.receive(eq(privateTxEnclaveKey), eq(participantKey))) when(enclave.receive(eq(privateTransactionLookupId), eq(participantKey)))
.thenReturn(new ReceiveResponse(encodePrivateTransaction, privacyGroupId, participantKey)); .thenReturn(new ReceiveResponse(encodePrivateTransaction, privacyGroupId, participantKey));
} }
@ -263,10 +263,10 @@ public class PrivateTransactionLocatorTest {
} }
private void mockEnclaveForNonExistingPayload(final Transaction pmt) { private void mockEnclaveForNonExistingPayload(final Transaction pmt) {
final String privateTxEnclaveKey = pmt.getData().orElseThrow().toBase64String(); final String privateTransactionLookupId = pmt.getData().orElseThrow().toBase64String();
final EnclaveClientException payloadNotFoundException = final EnclaveClientException payloadNotFoundException =
new EnclaveClientException(404, "Payload not found"); new EnclaveClientException(404, "Payload not found");
when(enclave.receive(eq(privateTxEnclaveKey), eq(participantKey))) when(enclave.receive(eq(privateTransactionLookupId), eq(participantKey)))
.thenThrow(payloadNotFoundException); .thenThrow(payloadNotFoundException);
} }

Loading…
Cancel
Save