-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
EIP-4844 support #2000
Merged
Merged
EIP-4844 support #2000
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dfcc17b
initial commit for EIP-4844
NickSneo 021bb65
added blob, commitment, proof support
NickSneo 40f6f15
added trsuted setup file
NickSneo 8a7a582
fixed rlp decoding and encoding
NickSneo 96b0857
consensys repo added to main gradle.build
NickSneo 9e90f63
tests added, failing build
NickSneo c9d10a8
added all tests, tested on Sepolia network
NickSneo 5254756
fixed java dump crash
NickSneo 14bd0f2
fixed comments, and loading of KZG lib
NickSneo e199d7f
load lib fix and simplification
NickSneo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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,47 @@ | ||
/* | ||
* Copyright 2024 Web3 Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package org.web3j.crypto; | ||
|
||
import org.apache.tuweni.bytes.Bytes; | ||
|
||
public class Blob { | ||
NickSneo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
final Bytes data; | ||
|
||
/** | ||
* Create a new Blob. | ||
* | ||
* @param data that represents the blob in Bytes. | ||
*/ | ||
public Blob(final Bytes data) { | ||
this.data = data; | ||
} | ||
|
||
/** | ||
* Create a new Blob. | ||
* | ||
* @param data that represents the blob in byte[]. | ||
*/ | ||
public Blob(final byte[] data) { | ||
this.data = Bytes.wrap(data); | ||
} | ||
|
||
/** | ||
* Get the data of the Blob. | ||
* | ||
* @return the data. | ||
*/ | ||
public Bytes getData() { | ||
return data; | ||
} | ||
} |
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,82 @@ | ||
/* | ||
* Copyright 2024 Web3 Labs Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package org.web3j.crypto; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.UncheckedIOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import ethereum.ckzg4844.CKZG4844JNI; | ||
import org.apache.tuweni.bytes.Bytes; | ||
|
||
public class BlobUtils { | ||
NickSneo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static { | ||
CKZG4844JNI.loadNativeLibrary(); | ||
} | ||
|
||
private static final byte blobCommitmentVersionKZG = 0x01; | ||
|
||
public static void loadTrustedSetupParameters() { | ||
NickSneo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try (InputStream inputStream = | ||
BlobUtils.class.getClassLoader().getResourceAsStream("trusted_setup.txt")) { | ||
assert inputStream != null; | ||
final BufferedReader reader = | ||
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); | ||
final int g1Count = Integer.parseInt(reader.readLine()); | ||
final int g2Count = Integer.parseInt(reader.readLine()); | ||
|
||
final ByteBuffer g1 = ByteBuffer.allocate(g1Count * CKZG4844JNI.BYTES_PER_G1); | ||
final ByteBuffer g2 = ByteBuffer.allocate(g2Count * CKZG4844JNI.BYTES_PER_G2); | ||
|
||
for (int i = 0; i < g1Count; i++) { | ||
g1.put(Bytes.fromHexString(reader.readLine()).toArray()); | ||
} | ||
for (int i = 0; i < g2Count; i++) { | ||
g2.put(Bytes.fromHexString(reader.readLine()).toArray()); | ||
} | ||
CKZG4844JNI.loadTrustedSetup(g1.array(), g1Count, g2.array(), g2Count); | ||
cfelde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} catch (final IOException ex) { | ||
throw new UncheckedIOException(ex); | ||
} | ||
} | ||
|
||
public static Bytes getCommitment(Blob blobData) { | ||
return Bytes.wrap(CKZG4844JNI.blobToKzgCommitment(blobData.data.toArray())); | ||
} | ||
|
||
public static Bytes getProof(Blob blobData, Bytes commitment) { | ||
return Bytes.wrap( | ||
CKZG4844JNI.computeBlobKzgProof(blobData.data.toArray(), commitment.toArray())); | ||
} | ||
|
||
public static boolean checkProofValidity(Blob blobData, Bytes commitment, Bytes proof) { | ||
return CKZG4844JNI.verifyBlobKzgProof( | ||
blobData.data.toArray(), commitment.toArray(), proof.toArray()); | ||
} | ||
|
||
public static Bytes kzgToVersionedHash(Bytes commitment) { | ||
byte[] hash = Hash.sha256(commitment.toArray()); | ||
hash[0] = blobCommitmentVersionKZG; | ||
return Bytes.wrap(hash); | ||
} | ||
NickSneo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static void freeTrustedSetup() { | ||
// the current trusted setup should be freed before a new one is loaded | ||
CKZG4844JNI.freeTrustedSetup(); | ||
} | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move to 2.0.12, is the latest one