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

Return Error if CKZG or BLS features are disabled, but are called #1448

Closed
wants to merge 6 commits into from

Conversation

rupam-04
Copy link

@rupam-04 rupam-04 commented May 23, 2024

Closes #1435

As of now I have only changed the PrecompileResult to enum and changed some code according to it. Please feel free to correct me if I have done anything wrong.

let a_aff = &extract_g1_input(&input[..G1_INPUT_ITEM_LENGTH], false)?;
let b_aff = &extract_g1_input(&input[G1_INPUT_ITEM_LENGTH..], false)?;
let a_aff = &extract_g1_input(&input[..G1_INPUT_ITEM_LENGTH], false).unwrap();
let b_aff = &extract_g1_input(&input[G1_INPUT_ITEM_LENGTH..], false).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why unwrap here?

Copy link
Author

@rupam-04 rupam-04 May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I use expect, then what panic msg should I give? Or should I use something else altogether?

@@ -53,7 +53,7 @@ pub(super) fn g1_msm(input: &Bytes, gas_limit: u64) -> PrecompileResult {
// NB: Scalar multiplications, MSMs and pairings MUST perform a subgroup check.
//
// So we set the subgroup_check flag to `true`
let p0_aff = &extract_g1_input(slice, true)?;
let p0_aff = &extract_g1_input(slice, true).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why unwrap?

@@ -64,14 +64,15 @@ pub(super) fn g1_msm(input: &Bytes, gas_limit: u64) -> PrecompileResult {
&extract_scalar_input(
&input[i * g1_mul::INPUT_LENGTH + G1_INPUT_ITEM_LENGTH
..i * g1_mul::INPUT_LENGTH + G1_INPUT_ITEM_LENGTH + SCALAR_LENGTH],
)?
)
.unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap?

Ok { gas_used: u64, output: Bytes },
Error { error_type: PrecompileError },
FatalError { msg: String },
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should structure this differently and still use the Result at the end it enables ?.

So this would mean having; Result<PrecompileOutput, PrecompileErrors>

Where:

enum PrecompileErrors {
    Error(PrecompileError),
    Fatal {
        msg: String
    },
}

And maybe where we are at it add PrecompileOutput

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay working on it!

@rupam-04
Copy link
Author

facing some issues with return types, would appreciate some pointers

@rupam-04
Copy link
Author

facing some issues with return types, would appreciate some pointers

mainly in PrecompileResult::ok

@rupam-04 rupam-04 requested a review from rakita May 25, 2024 09:56

/// A precompile operation result.
///
/// Returns either `Ok((gas_used, return_bytes))` or `Err(error)`.
pub type PrecompileResult = Result<(u64, Bytes), PrecompileError>;
pub enum PrecompileErrors {
Error(PrecompileError),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could implement impl From<PrecompileError> for PrecompileErrors {

And transform from previous return Err(Error::OutOfGas); to return Err(Error::OutOfGas.into());

@rakita
Copy link
Member

rakita commented May 25, 2024

facing some issues with return types, would appreciate some pointers

What kind of issues?

@rupam-04
Copy link
Author

rupam-04 commented May 25, 2024

facing some issues with return types, would appreciate some pointers

What kind of issues?

return type errors to be exact. I am not being able to figure out a solution

mismatched types
expected enum `Result<revm_precompile::PrecompileOutput, PrecompileErrors>`
   found enum `std::option::Option<revm_precompile::PrecompileOutput>`

at

PrecompileResult::ok(gas_used, out.into())

@rakita

@@ -29,6 +29,7 @@ hashbrown = "0.14"
auto_impl = "1.2"
bitvec = { version = "1", default-features = false, features = ["alloc"] }
bitflags = { version = "2.5.0", default-features = false }
revm-precompile = "7.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be imported, it is cyclic dependency

@rakita
Copy link
Member

rakita commented Jun 8, 2024

I will take this over

@rakita
Copy link
Member

rakita commented Jun 8, 2024

Closing this in favor of: #1499

@rakita rakita closed this Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return Error if CKZG or BLS features are disabled, but are called.
2 participants