Skip to content

[Safrole] Tests use truncated BLAKE2b-512 #6

Closed

Description

@ggwpez

The updated entropy accumulator is calculated by BLAKE2b256(accumulator ++ vrf) as per GP:

Screenshot 2024-06-30 at 00 14 49
Screenshot 2024-06-30 at 00 15 08

Using the following inputs:

  • Accumulator 0x2fa3f686df876995167e7c2e5d74c4c7b6e48f8068fe0e44208344d480f7904c from here
  • VRF 0xb2053e5a0852b9a5673f340d1cffe49f63f451e3b8b1e3b8d6c6ae731c888af1 from here
  • Concatenated 0x2fa3f686df876995167e7c2e5d74c4c7b6e48f8068fe0e44208344d480f7904cb2053e5a0852b9a5673f340d1cffe49f63f451e3b8b1e3b8d6c6ae731c888af1

Computing the Blake2b-256 hash of the concatenation yields:
0xb137ecb42ed3fe7df0281a459acd05e486bea724205cfdddc0b30efa0086c52f

as opposed to what is stated ↯:
0x9c2d3bce7aa0a5857c67a85247365d2035f7d9daec2b515e86086584ad5e8644 from here

However, using Blake2b-512 and truncating it to 32 bytes does yield the stated output. Which leads me to the assumption that the 512 variant was used instead of the proper 256 variant.

Rust test for demonstration purpose:

#[test]
fn hash_works() {
    let acc = array_bytes::hex2bytes("2fa3f686df876995167e7c2e5d74c4c7b6e48f8068fe0e44208344d480f7904c").unwrap();
    let vrf = array_bytes::hex2bytes("b2053e5a0852b9a5673f340d1cffe49f63f451e3b8b1e3b8d6c6ae731c888af1").unwrap();
    
    let concat = vec![acc, vrf].concat();
    
    let correct = sp_core::blake2_256(&concat);
    assert_eq!(array_bytes::bytes2hex("", correct), "b137ecb42ed3fe7df0281a459acd05e486bea724205cfdddc0b30efa0086c52f");
    
    let incorrect = &sp_core::blake2_512(&concat)[..32];
    assert_eq!(array_bytes::bytes2hex("", incorrect), "9c2d3bce7aa0a5857c67a85247365d2035f7d9daec2b515e86086584ad5e8644");
}

Activity

  1. added a commit that references this issue on May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions