Skip to content

Commit

Permalink
fix: comments, deprecate attr
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy committed Nov 19, 2024
1 parent 314ab53 commit 3ff838d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions crates/core/executor/src/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub type BoxedHook<'a> = Arc<RwLock<dyn Hook + Send + Sync + 'a>>;
/// The file descriptor through which to access `hook_ecrecover`.
pub const FD_ECRECOVER_HOOK: u32 = 5;

// note: we skip 6 because we have an eddsa hook in dev
// Note: we skip 6 because we have an eddsa hook in dev.

/// The file descriptor through which to access `hook_ecrecover_2`.
pub const FD_ECRECOVER_HOOK_2: u32 = 7;
Expand Down Expand Up @@ -81,7 +81,7 @@ impl<'a> Default for HookRegistry<'a> {
// Note: To ensure any `fd` value is synced with `zkvm/precompiles/src/io.rs`,
// add an assertion to the test `hook_fds_match` below.
(FD_ECRECOVER_HOOK, hookify(hook_ecrecover)),
(FD_ECRECOVER_HOOK_2, hookify(hook_ecrecover_2)),
(FD_ECRECOVER_HOOK_2, hookify(hook_ecrecover_v2)),
]);

Self { table }
Expand Down Expand Up @@ -122,9 +122,8 @@ pub struct HookEnv<'a, 'b: 'a> {
///
/// WARNING: This function is used to recover the public key outside of the zkVM context. These
/// values must be constrained by the zkVM for correctness.
///
/// Note: This hook will be deprecated in future versions.
#[must_use]
#[deprecated = "Use `hook_ecrecover_v2` instead."]
pub fn hook_ecrecover(_: HookEnv, buf: &[u8]) -> Vec<Vec<u8>> {
assert_eq!(buf.len(), 65 + 32, "ecrecover input should have length 65 + 32");
let (sig, msg_hash) = buf.split_at(65);
Expand Down Expand Up @@ -159,13 +158,15 @@ pub fn hook_ecrecover(_: HookEnv, buf: &[u8]) -> Vec<Vec<u8>> {
/// recovery ID.
/// - The message hash is 32 bytes.
///
/// The result is returned as a pair of bytes, where the first 32 bytes are the X coordinate
/// The result is returned as a status and a pair of bytes, where the first 32 bytes are the X coordinate
/// and the second 32 bytes are the Y coordinate of the decompressed point.
///
/// A status of 0 indicates that the public key could not be recovered.
///
/// WARNING: This function is used to recover the public key outside of the zkVM context. These
/// values must be constrained by the zkVM for correctness.
#[must_use]
pub fn hook_ecrecover_2(_: HookEnv, buf: &[u8]) -> Vec<Vec<u8>> {
pub fn hook_ecrecover_v2(_: HookEnv, buf: &[u8]) -> Vec<Vec<u8>> {
assert_eq!(buf.len(), 65 + 32, "ecrecover input should have length 65 + 32");
let (sig, msg_hash) = buf.split_at(65);
let sig: &[u8; 65] = sig.try_into().unwrap();
Expand All @@ -179,8 +180,8 @@ pub fn hook_ecrecover_2(_: HookEnv, buf: &[u8]) -> Vec<Vec<u8>> {
recovery_id ^= 1;
};
let recid = RecoveryId::from_byte(recovery_id).expect("Computed recovery ID is invalid!");

// recovery failed, indicate to the caller
// Attempting to recvover the public key has failed, write a 0 to indicate to the caller.
let Ok(recovered_key) = VerifyingKey::recover_from_prehash(&msg_hash[..], &sig, recid) else {
return vec![vec![0]];
};
Expand Down

0 comments on commit 3ff838d

Please sign in to comment.