fix goquorum privacy (#2224)

* fix goquorum privacy

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>

* fix submodule

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
pull/2228/head
Stefan Pingel 4 years ago committed by GitHub
parent eaafaaaae8
commit f6d50dcab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/WorldUpdater.java
  2. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetContractCreationProcessor.java
  3. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetMessageCallProcessor.java
  4. 13
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/GoQuorumMutablePrivateWorldStateUpdater.java
  5. 2
      ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java

@ -14,6 +14,8 @@
*/ */
package org.hyperledger.besu.ethereum.core; package org.hyperledger.besu.ethereum.core;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import java.util.Collection; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
@ -90,6 +92,17 @@ public interface WorldUpdater extends MutableWorldView {
*/ */
EvmAccount getAccount(Address address); EvmAccount getAccount(Address address);
/**
* Retrieves the senders account, returning a modifiable object (whose updates are accumulated by
* this updater).
*
* @param frame the current message frame.
* @return the account {@code address}, or {@code null} if the account does not exist.
*/
default EvmAccount getSenderAccount(final MessageFrame frame) {
return getAccount(frame.getSenderAddress());
}
/** /**
* Deletes the provided account. * Deletes the provided account.
* *

@ -110,8 +110,8 @@ public class MainnetContractCreationProcessor extends AbstractMessageProcessor {
LOG.trace("Executing contract-creation"); LOG.trace("Executing contract-creation");
} }
try { try {
final MutableAccount sender =
frame.getWorldState().getOrCreateSenderAccount(frame.getSenderAddress()).getMutable(); final MutableAccount sender = frame.getWorldState().getSenderAccount(frame).getMutable();
sender.decrementBalance(frame.getValue()); sender.decrementBalance(frame.getValue());
final MutableAccount contract = final MutableAccount contract =

@ -85,8 +85,7 @@ public class MainnetMessageCallProcessor extends AbstractMessageProcessor {
* of the world state of this executor. * of the world state of this executor.
*/ */
private void transferValue(final MessageFrame frame) { private void transferValue(final MessageFrame frame) {
final MutableAccount senderAccount = final MutableAccount senderAccount = frame.getWorldState().getSenderAccount(frame).getMutable();
frame.getWorldState().getOrCreateSenderAccount(frame.getSenderAddress()).getMutable();
// The yellow paper explicitly states that if the recipient account doesn't exist at this // The yellow paper explicitly states that if the recipient account doesn't exist at this
// point, it is created. // point, it is created.
final MutableAccount recipientAccount = final MutableAccount recipientAccount =

@ -18,6 +18,7 @@ import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.EvmAccount; import org.hyperledger.besu.ethereum.core.EvmAccount;
import org.hyperledger.besu.ethereum.core.UpdateTrackingAccount; import org.hyperledger.besu.ethereum.core.UpdateTrackingAccount;
import org.hyperledger.besu.ethereum.core.WorldUpdater; import org.hyperledger.besu.ethereum.core.WorldUpdater;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
// This class uses a public WorldUpdater and a private WorldUpdater to provide a // This class uses a public WorldUpdater and a private WorldUpdater to provide a
// MutableWorldStateUpdater that can read and write from the private world state and can read from // MutableWorldStateUpdater that can read and write from the private world state and can read from
@ -32,6 +33,16 @@ public class GoQuorumMutablePrivateWorldStateUpdater
@Override @Override
public EvmAccount getOrCreateSenderAccount(final Address address) { public EvmAccount getOrCreateSenderAccount(final Address address) {
return new UpdateTrackingAccount<EvmAccount>(publicWorldUpdater.getOrCreate(address)); return new UpdateTrackingAccount<>(publicWorldUpdater.getOrCreate(address));
}
@Override
public EvmAccount getSenderAccount(final MessageFrame frame) {
final Address senderAddress = frame.getSenderAddress();
if (senderAddress.equals(frame.getOriginatorAddress())) {
return new UpdateTrackingAccount<>(publicWorldUpdater.getOrCreate(senderAddress));
} else {
return getAccount(senderAddress);
}
} }
} }

@ -206,7 +206,7 @@ public class StateTestSubCommand implements Runnable {
if (coinbase != null && coinbase.isEmpty()) { if (coinbase != null && coinbase.isEmpty()) {
worldStateUpdater.deleteAccount(coinbase.getAddress()); worldStateUpdater.deleteAccount(coinbase.getAddress());
} }
final Account sender = worldStateUpdater.getOrCreateSenderAccount(transaction.getSender()); final Account sender = worldStateUpdater.getAccount(transaction.getSender());
if (sender != null && sender.isEmpty()) { if (sender != null && sender.isEmpty()) {
worldStateUpdater.deleteAccount(sender.getAddress()); worldStateUpdater.deleteAccount(sender.getAddress());
} }

Loading…
Cancel
Save