Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eip1559 private txs #950

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
560a21c
add eth_signTransaction
gfukushima Jun 27, 2023
9193fb2
add bouncycastle to test in the core package
gfukushima Jun 27, 2023
a1fcf02
Add eth_sendTransaction
gfukushima Jun 28, 2023
f795d52
Change DefaultTestBase method name to setupWeb3Signer
gfukushima Jun 29, 2023
ddcb571
Change account used by eth_accounts and IT base
gfukushima Jun 29, 2023
439c9fb
Call setupWeb3Signer
gfukushima Jun 30, 2023
0e46208
Extend DefaultTestBase
gfukushima Jun 30, 2023
df52f8c
Integration tests fixes + spotless
gfukushima Jul 5, 2023
6e53e0a
Acceptance tests
gfukushima Jul 5, 2023
e83d585
Remove unused methods
gfukushima Jul 5, 2023
ac65c92
Some extra fixes
gfukushima Jul 6, 2023
bbe7b79
Merge branch 'master' into add_eth_sendTransaction
gfukushima Jul 6, 2023
4d07dcd
spotless
gfukushima Jul 6, 2023
e4d4643
Fix proxy integration tests
gfukushima Jul 6, 2023
cdb5625
Fix proxy integration tests
gfukushima Jul 6, 2023
35c2002
Fix proxy integration tests
gfukushima Jul 6, 2023
4f6dd05
Fix proxy integration tests
gfukushima Jul 6, 2023
0ebf80a
spotless
gfukushima Jul 6, 2023
42fe2f8
Merge remote-tracking branch '_gfukushima/add_eth_sendTransaction' in…
gfukushima Jul 6, 2023
8977e48
spotless
gfukushima Jul 6, 2023
cf81a1c
AT fix
gfukushima Jul 6, 2023
bfe1743
Add eea_sendTransaction
gfukushima Jul 7, 2023
70482fc
spotless
gfukushima Jul 7, 2023
9df4ef8
Support maxPriorityFeePerGas and maxFeePerGas
siladu Jul 7, 2023
fdede82
Simplify Transaction interface
siladu Jul 10, 2023
fe21f28
Encode/Decode 1559 transactions for public and private transactions
siladu Jul 11, 2023
5339f55
Merge remote-tracking branch 'upstream/master' into eip1559-private-txs
jframe Nov 29, 2023
6934134
remove changes superseded on main
jframe Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,29 @@ private BesuPrivateTransaction(

@Override
protected RawPrivateTransaction createTransaction() {
return RawPrivateTransaction.createTransaction(
nonce,
transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE),
transactionJsonParameters.gas().orElse(DEFAULT_GAS),
transactionJsonParameters.receiver().orElse(DEFAULT_TO),
transactionJsonParameters.data().orElse(DEFAULT_DATA),
transactionJsonParameters.privateFrom(),
privacyGroupId,
Restriction.fromString(transactionJsonParameters.restriction()));
if (transactionJsonParameters.maxPriorityFeePerGas().isPresent()
&& transactionJsonParameters.maxFeePerGas().isPresent()) {
return RawPrivateTransaction.createTransaction(
chainId,
nonce,
transactionJsonParameters.maxPriorityFeePerGas().orElseThrow(),
transactionJsonParameters.maxFeePerGas().orElseThrow(),
transactionJsonParameters.gas().orElse(DEFAULT_GAS),
transactionJsonParameters.receiver().orElse(DEFAULT_TO),
transactionJsonParameters.data().orElse(DEFAULT_DATA),
transactionJsonParameters.privateFrom(),
privacyGroupId,
Restriction.fromString(transactionJsonParameters.restriction()));
} else {
return RawPrivateTransaction.createTransaction(
nonce,
transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE),
transactionJsonParameters.gas().orElse(DEFAULT_GAS),
transactionJsonParameters.receiver().orElse(DEFAULT_TO),
transactionJsonParameters.data().orElse(DEFAULT_DATA),
transactionJsonParameters.privateFrom(),
privacyGroupId,
Restriction.fromString(transactionJsonParameters.restriction()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,28 @@ public String toString() {

@Override
protected RawPrivateTransaction createTransaction() {
return RawPrivateTransaction.createTransaction(
nonce,
transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE),
transactionJsonParameters.gas().orElse(DEFAULT_GAS),
transactionJsonParameters.receiver().orElse(DEFAULT_TO),
transactionJsonParameters.data().orElse(DEFAULT_DATA),
transactionJsonParameters.privateFrom(),
privateFor,
Restriction.fromString(transactionJsonParameters.restriction()));
if (isEip1559()) {
return RawPrivateTransaction.createTransaction(
chainId,
nonce,
transactionJsonParameters.maxPriorityFeePerGas().orElseThrow(),
transactionJsonParameters.maxFeePerGas().orElseThrow(),
transactionJsonParameters.gas().orElse(DEFAULT_GAS),
transactionJsonParameters.receiver().orElse(DEFAULT_TO),
transactionJsonParameters.data().orElse(DEFAULT_DATA),
transactionJsonParameters.privateFrom(),
privateFor,
Restriction.fromString(transactionJsonParameters.restriction()));
} else {
return RawPrivateTransaction.createTransaction(
nonce,
transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE),
transactionJsonParameters.gas().orElse(DEFAULT_GAS),
transactionJsonParameters.receiver().orElse(DEFAULT_TO),
transactionJsonParameters.data().orElse(DEFAULT_DATA),
transactionJsonParameters.privateFrom(),
privateFor,
Restriction.fromString(transactionJsonParameters.restriction()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
import tech.pegasys.web3signer.core.service.jsonrpc.handlers.sendtransaction.transaction.PrivateTransaction;

import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.web3j.crypto.Sign.SignatureData;
import org.web3j.crypto.transaction.type.Transaction1559;
import org.web3j.crypto.transaction.type.TransactionType;
import org.web3j.protocol.eea.crypto.PrivateTransactionDecoder;
import org.web3j.protocol.eea.crypto.RawPrivateTransaction;
import org.web3j.protocol.eea.crypto.SignedRawPrivateTransaction;
import org.web3j.utils.Base64String;
import org.web3j.utils.Numeric;
Expand Down Expand Up @@ -92,6 +97,62 @@ public void rlpEncodesTransaction() {
assertThat(trimLeadingZeroes(decodedSignatureData.getS())).isEqualTo(new byte[] {3});
}

@Disabled("TODO SLD")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable!

@Test
public void rlpEncodesEip1559Transaction() {
final EeaSendTransactionJsonParameters params =
new EeaSendTransactionJsonParameters(
"0x7577919ae5df4941180eac211965f275cdce314d",
"ZlapEsl9qDLPy/e88+/6yvCUEVIvH83y0N4A6wHuKXI=",
"restricted");
params.receiver("0xd46e8dd67c5d32be8058bb8eb970870f07244567");
params.gas("0x76c0");
params.maxPriorityFeePerGas("0x9184e72a000");
params.maxFeePerGas("0x9184e72a001");
params.value("0x0");
params.nonce("0x1");
params.data(
"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675");
params.privateFor(new String[] {"GV8m0VZAccYGAAYMBuYQtKEj0XtpXeaw2APcoBmtA2w="});

privateTransaction =
EeaPrivateTransaction.from(1337L, params, () -> BigInteger.ZERO, new JsonRpcRequestId(1));

final SignatureData signatureData = null;
final byte[] rlpEncodedBytes = privateTransaction.rlpEncode(signatureData);
final String rlpString = Numeric.toHexString(prependEip1559TransactionType(rlpEncodedBytes));

final RawPrivateTransaction decodedTransaction = PrivateTransactionDecoder.decode(rlpString);
final Transaction1559 decoded1559Transaction =
(Transaction1559) decodedTransaction.getTransaction();
assertThat(decoded1559Transaction.getTo())
.isEqualTo("0xd46e8dd67c5d32be8058bb8eb970870f07244567");
assertThat(decoded1559Transaction.getGasLimit()).isEqualTo(decodeQuantity("0x76c0"));
assertThat(decoded1559Transaction.getMaxPriorityFeePerGas())
.isEqualTo(decodeQuantity("0x9184e72a000"));
assertThat(decoded1559Transaction.getMaxFeePerGas()).isEqualTo(decodeQuantity("0x9184e72a001"));
assertThat(decoded1559Transaction.getNonce()).isEqualTo(decodeQuantity("0x1"));
assertThat(decoded1559Transaction.getValue()).isEqualTo(decodeQuantity("0x0"));
assertThat(decoded1559Transaction.getData())
.isEqualTo(
"d46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675");
assertThat(decodedTransaction.getRestriction()).isEqualTo(Restriction.RESTRICTED);

final Base64String expectedDecodedPrivateFrom = params.privateFrom();
final Base64String expectedDecodedPrivateFor = params.privateFor().get().get(0);

assertThat(decodedTransaction.getPrivateFrom()).isEqualTo(expectedDecodedPrivateFrom);
assertThat(decodedTransaction.getPrivateFor().get().get(0))
.isEqualTo(expectedDecodedPrivateFor);
}

private static byte[] prependEip1559TransactionType(byte[] bytesToSign) {
return ByteBuffer.allocate(bytesToSign.length + 1)
.put(TransactionType.EIP1559.getRlpType())
.put(bytesToSign)
.array();
}

@Test
@SuppressWarnings("unchecked")
public void createsJsonEeaRequest() {
Expand Down