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

[4844] KZGPointEvalPrecompiled - Use PrecompileContractResult methods to halt and succeed #5691

Merged
Changes from all commits
Commits
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 @@ -103,62 +103,41 @@ public PrecompileContractResult computePrecompile(
final Bytes input, @NotNull final MessageFrame messageFrame) {

if (input.size() != 192) {
return new PrecompileContractResult(
Bytes.EMPTY,
false,
MessageFrame.State.COMPLETED_FAILED,
Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
return PrecompileContractResult.halt(
null, Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
}
Bytes32 versionedHash = Bytes32.wrap(input.slice(0, 32));
Bytes z = input.slice(32, 32);
Bytes y = input.slice(64, 32);
Bytes commitment = input.slice(96, 48);
Bytes proof = input.slice(144, 48);
if (versionedHash.get(0) != 0x01) { // unsupported hash version
return new PrecompileContractResult(
Bytes.EMPTY,
false,
MessageFrame.State.COMPLETED_FAILED,
Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
return PrecompileContractResult.halt(
null, Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
} else {
byte[] hash = Hash.sha256(commitment).toArray();
hash[0] = 0x01;
if (!versionedHash.equals(Bytes32.wrap(hash))) {
return new PrecompileContractResult(
Bytes.EMPTY,
false,
MessageFrame.State.COMPLETED_FAILED,
Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
return PrecompileContractResult.halt(
null, Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
}
}
PrecompileContractResult result;
try {
boolean proved =
CKZG4844JNI.verifyKzgProof(
commitment.toArray(), z.toArray(), y.toArray(), proof.toArray());

if (proved) {
result =
new PrecompileContractResult(
successResult, false, MessageFrame.State.COMPLETED_SUCCESS, Optional.empty());
return PrecompileContractResult.success(successResult);
} else {
result =
new PrecompileContractResult(
Bytes.EMPTY,
false,
MessageFrame.State.COMPLETED_FAILED,
Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
return PrecompileContractResult.halt(
null, Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
}
return result;
} catch (RuntimeException kzgFailed) {
System.out.println(kzgFailed.getMessage());
result =
new PrecompileContractResult(
Bytes.EMPTY,
false,
MessageFrame.State.COMPLETED_FAILED,
Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));

return PrecompileContractResult.halt(
null, Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
}
return result;
}
}
Loading