use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class TraceTransactionIntegrationTest method shouldTraceSStoreOperation.
@Test
public void shouldTraceSStoreOperation() {
final KeyPair keyPair = SignatureAlgorithmFactory.getInstance().generateKeyPair();
final Transaction createTransaction = Transaction.builder().type(TransactionType.FRONTIER).gasLimit(300_000).gasPrice(Wei.ZERO).nonce(0).payload(Bytes.fromHexString(CONTRACT_CREATION_DATA)).value(Wei.ZERO).signAndBuild(keyPair);
final BlockHeader genesisBlockHeader = genesisBlock.getHeader();
final MutableWorldState worldState = worldStateArchive.getMutable(genesisBlockHeader.getStateRoot(), genesisBlockHeader.getHash()).get();
final WorldUpdater createTransactionUpdater = worldState.updater();
TransactionProcessingResult result = transactionProcessor.processTransaction(blockchain, createTransactionUpdater, genesisBlockHeader, createTransaction, genesisBlockHeader.getCoinbase(), blockHashLookup, false, TransactionValidationParams.blockReplay());
assertThat(result.isSuccessful()).isTrue();
final Account createdContract = createTransactionUpdater.getTouchedAccounts().stream().filter(account -> !account.getCode().isEmpty()).findAny().get();
createTransactionUpdater.commit();
// Now call the transaction to execute the SSTORE.
final DebugOperationTracer tracer = new DebugOperationTracer(new TraceOptions(true, true, true));
final Transaction executeTransaction = Transaction.builder().type(TransactionType.FRONTIER).gasLimit(300_000).gasPrice(Wei.ZERO).nonce(1).payload(Bytes.fromHexString(CALL_SET_OTHER)).to(createdContract.getAddress()).value(Wei.ZERO).signAndBuild(keyPair);
final WorldUpdater storeUpdater = worldState.updater();
result = transactionProcessor.processTransaction(blockchain, storeUpdater, genesisBlockHeader, executeTransaction, genesisBlockHeader.getCoinbase(), tracer, blockHashLookup, false);
assertThat(result.isSuccessful()).isTrue();
// No storage changes before the SSTORE call.
TraceFrame frame = tracer.getTraceFrames().get(170);
assertThat(frame.getOpcode()).isEqualTo("DUP6");
assertStorageContainsExactly(frame);
// Storage changes show up in the SSTORE frame.
frame = tracer.getTraceFrames().get(171);
assertThat(frame.getOpcode()).isEqualTo("SSTORE");
assertStorageContainsExactly(frame, entry("0x01", "0x6261720000000000000000000000000000000000000000000000000000000006"));
// And storage changes are still present in future frames.
frame = tracer.getTraceFrames().get(172);
assertThat(frame.getOpcode()).isEqualTo("PUSH2");
assertStorageContainsExactly(frame, entry("0x01", "0x6261720000000000000000000000000000000000000000000000000000000006"));
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class PeerDiscoveryAgentTest method testNodeRecordCreated.
@Test
public void testNodeRecordCreated() {
KeyPair keyPair = SIGNATURE_ALGORITHM.get().createKeyPair(SIGNATURE_ALGORITHM.get().createPrivateKey(Bytes32.fromHexString("0xb71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")));
final MockPeerDiscoveryAgent agent = helper.startDiscoveryAgent(helper.agentBuilder().nodeKey(NodeKeyUtils.createFrom(keyPair)).advertisedHost("127.0.0.1").bindPort(30303));
assertThat(agent.getAdvertisedPeer().isPresent()).isTrue();
assertThat(agent.getAdvertisedPeer().get().getNodeRecord().isPresent()).isTrue();
final NodeRecord nodeRecord = agent.getAdvertisedPeer().get().getNodeRecord().get();
assertThat(nodeRecord.getNodeId()).isNotNull();
assertThat(nodeRecord.getIdentityScheme()).isNotNull();
assertThat(nodeRecord.getSignature()).isNotNull();
assertThat(nodeRecord.getSeq()).isNotNull();
assertThat(nodeRecord.get("eth")).isNotNull();
assertThat(nodeRecord.get("eth")).isEqualTo(Collections.singletonList(Collections.singletonList(Bytes.EMPTY)));
assertThat(nodeRecord.asEnr()).isEqualTo("enr:-JC4QOfroMOa1sB6ajxcBKdWn3s9S4Ojl33pbRm72S5FnCwyZfskmjkJvZznQaWNTrOHrnKxw1R9xMm9rl" + "EGOcsOyscBg2V0aMLBgIJpZIJ2NIJpcIR_AAABiXNlY3AyNTZrMaEDymNMrg1JrLQB2KTGtv6MVbcNEV" + "v0AHacwUAPMljNMTiDdGNwAoN1ZHCCdl8");
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class BootNodesGenesisSetupTest method setUp.
@Before
public void setUp() throws Exception {
int nodeAP2pBindingPort;
int nodeBP2pBindingPort;
try (ServerSocket nodeASocket = new ServerSocket(0);
ServerSocket nodeBSocket = new ServerSocket(0)) {
nodeAP2pBindingPort = nodeASocket.getLocalPort();
nodeBP2pBindingPort = nodeBSocket.getLocalPort();
}
final KeyPair nodeAKeyPair = createKeyPair(Bytes32.fromHexString("0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"));
final KeyPair nodeBKeyPair = createKeyPair(Bytes32.fromHexString("0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3"));
nodeA = besu.createNode("nodeA", nodeBuilder -> configureNode(nodeBuilder, nodeAP2pBindingPort, nodeAKeyPair, nodeBKeyPair.getPublicKey(), nodeBP2pBindingPort));
nodeB = besu.createNode("nodeB", nodeBuilder -> configureNode(nodeBuilder, nodeBP2pBindingPort, nodeBKeyPair, nodeAKeyPair.getPublicKey(), nodeAP2pBindingPort));
cluster.start(nodeA, nodeB);
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class SECP256R1AcceptanceTest method setUp.
@Before
public void setUp() throws Exception {
KeyPair minerNodeKeyPair = createKeyPair(MINER_NODE_PRIVATE_KEY);
KeyPair otherNodeKeyPair = createKeyPair(OTHER_NODE_PRIVATE_KEY);
final ClusterConfiguration clusterConfiguration = new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build();
noDiscoveryCluster = new Cluster(clusterConfiguration, net);
minerNode = besu.createNodeWithNonDefaultSignatureAlgorithm("minerNode", GENESIS_FILE, minerNodeKeyPair);
noDiscoveryCluster.start(minerNode);
otherNode = besu.createNodeWithNonDefaultSignatureAlgorithm("otherNode", GENESIS_FILE, otherNodeKeyPair, List.of(minerNode));
noDiscoveryCluster.addNode(otherNode);
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class BlockDataGenerator method generateKeyPair.
public KeyPair generateKeyPair() {
final java.security.KeyPair rawKeyPair = keyPairGenerator.generateKeyPair();
final BCECPrivateKey privateKey = (BCECPrivateKey) rawKeyPair.getPrivate();
final BCECPublicKey publicKey = (BCECPublicKey) rawKeyPair.getPublic();
final BigInteger privateKeyValue = privateKey.getD();
// Ethereum does not use encoded public keys like bitcoin - see
// https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm for details
// Additionally, as the first bit is a constant prefix (0x04) we ignore this value
final byte[] publicKeyBytes = publicKey.getQ().getEncoded(false);
final BigInteger publicKeyValue = new BigInteger(1, Arrays.copyOfRange(publicKeyBytes, 1, publicKeyBytes.length));
return new KeyPair(signatureAlgorithm.createPrivateKey(privateKeyValue), signatureAlgorithm.createPublicKey(publicKeyValue));
}
Aggregations