-
-
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 all 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,67 @@ | ||
/* | ||
* 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.util.Objects; | ||
|
||
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; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Blob blob = (Blob) o; | ||
return Objects.equals(data, blob.data); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return data != null ? data.hashCode() : 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Blob{" + "data=" + 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,51 @@ | ||
/* | ||
* 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 ethereum.ckzg4844.CKZG4844JNI; | ||
import org.apache.tuweni.bytes.Bytes; | ||
|
||
public class BlobUtils { | ||
NickSneo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private static final byte blobCommitmentVersionKZG = 0x01; | ||
private static final String trustedSetupFilePath = "/trusted_setup.txt"; | ||
|
||
static { | ||
CKZG4844JNI.loadNativeLibrary(); | ||
loadTrustedSetupParameters(); | ||
} | ||
|
||
private static void loadTrustedSetupParameters() { | ||
CKZG4844JNI.loadTrustedSetupFromResource(BlobUtils.trustedSetupFilePath, BlobUtils.class); | ||
} | ||
|
||
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
|
||
} |
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