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

[Bug] Incorrect ssz::Encode implementation #448

Closed
blombern opened this issue Dec 9, 2023 · 0 comments · Fixed by #451
Closed

[Bug] Incorrect ssz::Encode implementation #448

blombern opened this issue Dec 9, 2023 · 0 comments · Fixed by #451
Labels
bug Something isn't working

Comments

@blombern
Copy link
Contributor

blombern commented Dec 9, 2023

Component

primitives

What version of Alloy are you on?

alloy-primitives v0.5.2

Operating System

macOS (Apple Silicon)

Describe the bug

From ssz_fixed_len method doc: Fixed-length objects must return a value which represents their length. Unless I'm missing something, shouldn't the Encode and Decode traits return the same value?

use alloy_primitives::{FixedBytes, B256};
use ssz::{Decode, Encode};

pub const BLS_PUBLIC_KEY_BYTES_LEN: usize = 48;
pub type BlsPublicKey = FixedBytes<BLS_PUBLIC_KEY_BYTES_LEN>;

fn main() {
    let len_e = <B256 as Encode>::ssz_fixed_len();
    let len_d = <B256 as Decode>::ssz_fixed_len();
    // prints: 4 32
    println!("{} {}", len_e, len_d);

    let len_e = <BlsPublicKey as Encode>::ssz_fixed_len();
    let len_d = <BlsPublicKey as Decode>::ssz_fixed_len();
    // prints: 4 48
    println!("{} {}", len_e, len_d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant