StarkSharp icon indicating copy to clipboard operation
StarkSharp copied to clipboard

PedersenArrayHash() calculation result is incorrect

Open joellai opened this issue 1 year ago • 1 comments

Hello Devs,

I noticed that the PedersenArrayHash() in Signature.cs is incorrect. I input the same elements for the Starknet SDK of Rust and Golang, which output the same result. However, the StarkSharp outputted a different result.

Input

[ 1, 3538590913404233637517614645285142862713314140114486938298183985940539460932, 497459341718103305379775550295558034030444673111452004986708794815896844186, 0, 3, 3, 10, 0, 2349594881967891698438073325871558009652837958216346624877686666399433011989 ]

Rust/Golang Output

0 first hash 2001140082530619239661729809084578298299223810202097622761632384561112390979 1 step by step hash 1 311766089032003537342301931868165807408839182518563601648805493012214670789 2 step by step hash 2 409299662317394734010242556943485696490867494746095977933912908679434486230 3 step by step hash 3 3544680985580575451654102065890237273226071942532919953923647064130257797035 4 step by step hash 4 1694645464789959294649633363301023176712257932436717772916947362498927245977 5 step by step hash 5 2049234278024675651208441937139014934041229758597334712848827754209586347611 6 step by step hash 6 2052323146660256048559058754046579884115029424600670470229139687270883198364 7 step by step hash 7 3379412601795784745342887874690205390240389452482815032532959591164516959626 8 step by step hash 8 3453252817372726438334118099310208164748791134485343218649384777581276094980

StarkSharp Output

Index 0 ecPoint 33922981744964762448906583458441958063430293016044195418749763900998629453

Index 1 ecPoint 3475401478704216931563232017617895323988035382114131484049602477327639669281

Index 2 ecPoint 1346378196977066433825255616811665020882544039181493634339735768403554478028

Index 3 ecPoint 1078863538462208452288956867693447486806814847495019063552325733886961944589

Index 4 ecPoint 1606533231116901221471162150913243039739645764576763670745651032970602591373

Index 5 ecPoint 687441458604678304385823993384637710501455803307755382790046322017172601926

Index 6 ecPoint 2976490589757522179129477055864518845698000653032470684903391980283111750999

Index 7 ecPoint 1497264336901688323664691090477069380243689755323701832977832686290909463858

Index 8 ecPoint 2293967605799097265545559565629270454116479023895046442159210996033942565135

How I call

  BigInteger[] testInput = new[]
    {
        BigInteger.Parse("1"),
        BigInteger.Parse("3538590913404233637517614645285142862713314140114486938298183985940539460932"),
        BigInteger.Parse("497459341718103305379775550295558034030444673111452004986708794815896844186"),
        BigInteger.Parse("0"),
        BigInteger.Parse("3"),
        BigInteger.Parse("3"),
        BigInteger.Parse("10"),
        BigInteger.Parse("0"),
        BigInteger.Parse("2349594881967891698438073325871558009652837958216346624877686666399433011989"),
    };


    ECDSA.PedersenArrayHash(testInput);

One more thing, one file misses a }, so the unity results an error.

joellai avatar Feb 21 '24 09:02 joellai

Hi @joellai I think it should use Aggregate in PedersenArrayHash function. I fixed this issue here (https://github.com/web3p/StarkSharp/commit/b5e7b6fa4f4449f77594cc75b8b6659dcbadfe61)

sc0Vu avatar Jul 22 '24 15:07 sc0Vu