-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 #2000 from web3j/nicks/eip-4844
EIP-4844 support
- Loading branch information
Showing
22 changed files
with
5,146 additions
and
11 deletions.
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 { | ||
|
||
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 { | ||
|
||
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); | ||
} | ||
} |
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.