-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from web3j/nicks/eip-tx-types
EIP Transaction Types Added
- Loading branch information
Showing
7 changed files
with
225 additions
and
3 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions
54
docs/transactions/EIP_transaction_types/eip1559_transaction.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## EIP-1559 Transaction | ||
|
||
Ethereum historically priced transaction fees using a simple auction mechanism, where users send transactions with bids | ||
("gasprices") and miners choose transactions with the highest bids, and transactions that get included pay the bid that | ||
they specify. This leads to several large sources of inefficiency: | ||
|
||
- Mismatch between volatility of transaction fee levels and social cost of transactions | ||
- Needless delays for users | ||
- Inefficiencies of first price auctions | ||
- Instability of blockchains with no block reward | ||
|
||
With EIP-1559, there will be a discrete “base fee” for transactions to be included in the next block. For users or | ||
applications that want to prioritize their transaction, they can add a “tip,” which is called a “priority fee” to pay a | ||
miner for faster inclusion. | ||
|
||
### Spec | ||
Introduce a new EIP-2718 transaction type, with value `2(0x02)` and `TransactionPayload` for this transaction is `rlp([chain_id, | ||
nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, amount, data, access_list, signature_y_parity, | ||
signature_r, signature_s])`. | ||
|
||
The `GASPRICE (0x3a)` opcode return the `effective_gas_price`. | ||
|
||
### Example | ||
|
||
```java | ||
|
||
public void signedEip1559() throws SignatureException { | ||
Credentials credentials = Credentials.create("<privateKey>"); | ||
Web3j web3j = Web3j.build(new HttpService("<nodeUrl>")); | ||
|
||
final RawTransaction rawTransaction = createEip1559RawTransaction(); | ||
|
||
final byte[] signedMessage = | ||
TransactionEncoder.signMessage(rawTransaction, credentials); | ||
final String signedHexMessage = Numeric.toHexString(signedMessage); | ||
|
||
EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(signedHexMessage).send(); | ||
|
||
System.out.println("Transaction hash: " + ethSendTransaction.getTransactionHash()); | ||
System.out.println("Tx Receipt = " + web3j.ethGetTransactionReceipt(ethSendTransaction.getTransactionHash()).send().getTransactionReceipt()); | ||
|
||
} | ||
|
||
private static RawTransaction createEip1559RawTransaction() { | ||
return RawTransaction.createEtherTransaction( | ||
3L, | ||
BigInteger.valueOf(0), | ||
BigInteger.valueOf(30000), | ||
"0x627306090abab3a6e1400e9345bc60c78a8bef57", | ||
BigInteger.valueOf(123), | ||
BigInteger.valueOf(5678), | ||
BigInteger.valueOf(1100000)); | ||
} | ||
``` |
55 changes: 55 additions & 0 deletions
55
docs/transactions/EIP_transaction_types/eip2930_transaction.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## EIP 2930 Transaction | ||
|
||
Adds a transaction type which contains an `accessList`, a list of addresses and storage keys that the transaction plans | ||
to access: these addresses and storage keys are added into the `accessed_addresses` and `accessed_storage_keys` global sets. | ||
Accesses outside the list are possible, but become more expensive. | ||
|
||
### Spec | ||
The new EIP-2718 `TransactionType = 1(0x01)` and TransactionPayload for this transaction is `rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, | ||
accessList, signatureYParity, signatureR, signatureS])`. | ||
|
||
### Example | ||
|
||
```java | ||
public void signedEip2930() throws SignatureException { | ||
Credentials credentials = Credentials.create("<privateKey>"); | ||
Web3j web3j = Web3j.build(new HttpService("<nodeUrl>")); | ||
|
||
final RawTransaction rawTransaction = createEip2930RawTransaction(); | ||
|
||
final byte[] signedMessage = | ||
TransactionEncoder.signMessage(rawTransaction, credentials); | ||
final String signedHexMessage = Numeric.toHexString(signedMessage); | ||
|
||
EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(signedHexMessage).send(); | ||
|
||
System.out.println("Transaction hash: " + ethSendTransaction.getTransactionHash()); | ||
System.out.println("Tx Receipt = " + web3j.ethGetTransactionReceipt(ethSendTransaction.getTransactionHash()).send().getTransactionReceipt()); | ||
|
||
} | ||
|
||
private static RawTransaction createEip2930RawTransaction() { | ||
// Test example from https://eips.ethereum.org/EIPS/eip-2930 | ||
List<AccessListObject> accessList = Stream.of( | ||
new AccessListObject( | ||
"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", | ||
Stream.of( | ||
"0x0000000000000000000000000000000000000000000000000000000000000003", | ||
"0x0000000000000000000000000000000000000000000000000000000000000007") | ||
.collect(toList())), | ||
new AccessListObject( | ||
"0xbb9bc244d798123fde783fcc1c72d3bb8c189413", | ||
Collections.emptyList())) | ||
.collect(toList()); | ||
|
||
return RawTransaction.createTransaction( | ||
3L, | ||
BigInteger.valueOf(0), | ||
BigInteger.valueOf(30000), | ||
BigInteger.valueOf(500000), | ||
"0x627306090abab3a6e1400e9345bc60c78a8bef57", | ||
BigInteger.valueOf(1000000), | ||
"0x1000001111100000", | ||
accessList); | ||
} | ||
``` |
109 changes: 109 additions & 0 deletions
109
docs/transactions/EIP_transaction_types/eip4844_blob_transaction.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
## EIP-4844 Blob Transaction | ||
|
||
EIP-4844 introduces a new kind of transaction type to Ethereum “blob-carrying transactions” which contain a large amount of data | ||
that cannot be accessed by EVM execution, but whose commitment can be accessed. These blobs to be persisted in the beacon | ||
node for a short period of time. | ||
|
||
Full data sharding will still take a considerable amount of time to finish implementing and deploying. This EIP provides | ||
a stop-gap solution until that point by implementing the transaction format that would be used in sharding, | ||
but not actually sharding those transactions. Instead, the data from this transaction format is simply part of the beacon | ||
chain and is fully downloaded by all consensus nodes (but can be deleted after only a relatively short delay). Compared | ||
to full data sharding, this EIP has a reduced cap on the number of these transactions that can be included, corresponding | ||
to a target of ~0.375 MB per block and a limit of ~0.75 MB. | ||
|
||
![Lifetime of a blob TX](../../img/Transaction-Types/blobTx_lifetime.png) | ||
|
||
### Spec | ||
|
||
The new type of EIP-2718 transaction, “blob transaction”, where the TransactionType is `BLOB_TX_TYPE` = `Bytes1(0x03)`. | ||
The fields `chain_id`, `nonce`, `max_priority_fee_per_gas`, `max_fee_per_gas`, `gas_limit`, `value`, `data`, and `access_list` | ||
follow the same semantics as EIP-1559. | ||
|
||
The field `max_fee_per_blob_gas` is a `uint256` and the field `blob_versioned_hashes` represents a list of hash outputs | ||
from` kzg_to_versioned_hash`. | ||
|
||
![Blob Transaction](../../img/Transaction-Types/blobTx.png) | ||
|
||
### Networking | ||
|
||
We can send a signed EIP-4844 transaction to `eth_sendRawTransaction` and the raw form must be the network form. | ||
This means it includes the tx_payload_body, blobs, KZG commitments, and KZG proofs. | ||
|
||
Each of these elements are defined as follows: | ||
|
||
- <b>tx_payload_body</b> - is the TransactionPayloadBody of standard EIP-2718 blob transaction | ||
- <b>blobs</b> - list of Blob items | ||
- <b>commitments</b> - list of KZGCommitment of the corresponding blobs | ||
- <b>proofs</b> - list of KZGProof of the corresponding blobs and commitments | ||
|
||
|
||
### Example | ||
|
||
#### Prerequisites | ||
Before proceeding with the following code example, please ensure that the network you are working with has EIP-4844 support | ||
enabled. | ||
|
||
```java | ||
public class Web3App { | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
Credentials credentials = Credentials.create("<privateKey>"); | ||
Web3j web3j = Web3j.build(new HttpService("<nodeUrl>")); | ||
|
||
EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount( | ||
credentials.getAddress(), DefaultBlockParameterName.LATEST).send(); | ||
BigInteger nonce = ethGetTransactionCount.getTransactionCount(); | ||
System.out.println("nonce = " + nonce); | ||
|
||
RawTransaction rawTransaction = createEip4844RawTransaction(nonce); | ||
// Sign the transaction | ||
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials); | ||
String hexValue = Numeric.toHexString(signedMessage); | ||
// Send the transaction | ||
EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).send(); | ||
|
||
System.out.println("Transaction hash: " + ethSendTransaction.getTransactionHash()); | ||
System.out.println("Tx Receipt = " + web3j.ethGetTransactionReceipt(ethSendTransaction.getTransactionHash()).send().getTransactionReceipt()); | ||
|
||
// Tx Receipt = Optional[TransactionReceipt{transactionHash='0x79cfe2c65f1a039b372436cabcd964df1038c45e5d3ebf542af1afca3356a2bc', transactionIndex='0x19', | ||
// blockHash='0x118be795f782d2d72b38217254efea4817a1a544cd847537049cb5028f87d183', blockNumber='0x4fd448', cumulativeGasUsed='0x142da9', gasUsed='0x5208', | ||
// contractAddress='null', root='null', status='0x1', from='0x1ba43becc3ea96c37343b7cb18de7386ba29445b', to='0xff00000000000000000000000000000011155421', | ||
// logs=[], logsBloom='0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | ||
// 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | ||
// 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | ||
// 000000000000000000000000000000000000000000000000000000000000000000000000000000000000', revertReason='null', type='0x3', effectiveGasPrice='0x14e2779259'}] | ||
|
||
web3j.shutdown(); | ||
} | ||
|
||
private static RawTransaction createEip4844RawTransaction(BigInteger nonce) { | ||
List<Blob> blobs = new ArrayList<>(); | ||
|
||
blobs.add(new Blob("<blobData_in_Bytes>")); | ||
return RawTransaction.createTransaction( | ||
blobs, | ||
11155111L, | ||
nonce, | ||
BigInteger.valueOf(10_000_000_000L), | ||
BigInteger.valueOf(50_000_000_000L), | ||
BigInteger.valueOf(3_00_000L), | ||
"<toAddress>", | ||
BigInteger.valueOf(0), | ||
"", | ||
BigInteger.valueOf(25_689_969_947L)); | ||
} | ||
} | ||
``` | ||
|
||
If we just want to calculate KZG commitment and KZG proofs from a blob, we can do that using BlobUtils Class functions. | ||
|
||
```java | ||
Blob blob = new Blob( | ||
Numeric.hexStringToByteArray( | ||
loadResourceAsString("blob_data.txt"))); | ||
Bytes commitment = BlobUtils.getCommitment(blob); | ||
Bytes proofs = BlobUtils.getProof(blob, commitment); | ||
Bytes versionedHashes = BlobUtils.kzgToVersionedHash(commitment); | ||
BlobUtils.checkProofValidity(blob, commitment, proofs) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[ | ||
{"version": "4.10.0", "title": "", "aliases": ["latest"]} | ||
{"version": "4.11.0", "title": "", "aliases": ["latest"]} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters