From 12a9e7966fa80367dc2effa434b87e205cb50c71 Mon Sep 17 00:00:00 2001 From: thiagodeev Date: Thu, 15 Aug 2024 01:27:55 -0300 Subject: [PATCH] Remove ComputeHashOnElementsFelt func --- account/account.go | 10 +++++----- contracts/contracts.go | 6 +++--- curve/curve.go | 11 ----------- curve/curve_test.go | 6 +++--- hash/hash.go | 2 +- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/account/account.go b/account/account.go index 1a28da0f..47f41a31 100644 --- a/account/account.go +++ b/account/account.go @@ -181,7 +181,7 @@ func (account *Account) TransactionHashDeployAccount(tx rpc.DeployAccountType, c case rpc.DeployAccountTxn: calldata := []*felt.Felt{txn.ClassHash, txn.ContractAddressSalt} calldata = append(calldata, txn.ConstructorCalldata...) - calldataHash := curve.ComputeHashOnElementsFelt(calldata) + calldataHash := curve.PedersenArray(calldata...) versionFelt, err := new(felt.Felt).SetString(string(txn.Version)) if err != nil { @@ -261,7 +261,7 @@ func (account *Account) TransactionHashInvoke(tx rpc.InvokeTxnType) (*felt.Felt, return nil, ErrNotAllParametersSet } - calldataHash := curve.ComputeHashOnElementsFelt(txn.Calldata) + calldataHash := curve.PedersenArray(txn.Calldata...) txnVersionFelt, err := new(felt.Felt).SetString(string(txn.Version)) if err != nil { return nil, err @@ -282,7 +282,7 @@ func (account *Account) TransactionHashInvoke(tx rpc.InvokeTxnType) (*felt.Felt, return nil, ErrNotAllParametersSet } - calldataHash := curve.ComputeHashOnElementsFelt(txn.Calldata) + calldataHash := curve.PedersenArray(txn.Calldata...) txnVersionFelt, err := new(felt.Felt).SetString(string(txn.Version)) if err != nil { return nil, err @@ -387,7 +387,7 @@ func (account *Account) TransactionHashDeclare(tx rpc.DeclareTxnType) (*felt.Fel return nil, ErrNotAllParametersSet } - calldataHash := curve.ComputeHashOnElementsFelt([]*felt.Felt{txn.ClassHash}) + calldataHash := curve.PedersenArray(txn.ClassHash) txnVersionFelt, err := new(felt.Felt).SetString(string(txn.Version)) if err != nil { @@ -408,7 +408,7 @@ func (account *Account) TransactionHashDeclare(tx rpc.DeclareTxnType) (*felt.Fel return nil, ErrNotAllParametersSet } - calldataHash := curve.ComputeHashOnElementsFelt([]*felt.Felt{txn.ClassHash}) + calldataHash := curve.PedersenArray(txn.ClassHash) txnVersionFelt, err := new(felt.Felt).SetString(string(txn.Version)) if err != nil { diff --git a/contracts/contracts.go b/contracts/contracts.go index e8c719c2..3daa9458 100644 --- a/contracts/contracts.go +++ b/contracts/contracts.go @@ -61,11 +61,11 @@ func UnmarshalCasmClass(filePath string) (*CasmClass, error) { // Returns: // - *felt.Felt: the precomputed address as a *felt.Felt func PrecomputeAddress(deployerAddress *felt.Felt, salt *felt.Felt, classHash *felt.Felt, constructorCalldata []*felt.Felt) *felt.Felt { - return curve.ComputeHashOnElementsFelt([]*felt.Felt{ + return curve.PedersenArray( PREFIX_CONTRACT_ADDRESS, deployerAddress, salt, classHash, - curve.ComputeHashOnElementsFelt(constructorCalldata), - }) + curve.PedersenArray(constructorCalldata...), + ) } diff --git a/curve/curve.go b/curve/curve.go index a86ccee4..a2ce61aa 100644 --- a/curve/curve.go +++ b/curve/curve.go @@ -555,17 +555,6 @@ func ComputeHashOnElements(elems []*big.Int) (hash *big.Int) { return HashPedersenElements(elems) } -// ComputeHashOnElementsFelt computes the hash on elements of a Felt array. -// Does the same as ComputeHashOnElements, but receives and returns felt types. -// -// Parameters: -// - feltArr: A pointer to an array of Felt objects. -// Returns: -// - *felt.Felt: a pointer to a Felt object -func ComputeHashOnElementsFelt(feltArr []*felt.Felt) *felt.Felt { - return PedersenArray(feltArr...) -} - // Pedersen is a function that implements the Pedersen hash. // NOTE: This function just wraps the Juno implementation // (ref: https://github.com/NethermindEth/juno/blob/32fd743c774ec11a1bb2ce3dceecb57515f4873e/core/crypto/pedersen_hash.go#L20) diff --git a/curve/curve_test.go b/curve/curve_test.go index 5e5810ac..711c2475 100644 --- a/curve/curve_test.go +++ b/curve/curve_test.go @@ -290,7 +290,7 @@ func TestGeneral_MultAir(t *testing.T) { } } -// TestGeneral_ComputeHashOnElements is a test function that verifies the correctness of the ComputeHashOnElements and ComputeHashOnElementsFelt functions in the General package. +// TestGeneral_ComputeHashOnElements is a test function that verifies the correctness of the ComputeHashOnElements and PedersenArray functions in the General package. // // This function tests both functions by passing in different arrays of big.Int elements and comparing the computed hash with the expected hash. // It checks the behavior of the functions when an empty array is passed as input, as well as when an array with multiple elements is passed. @@ -302,7 +302,7 @@ func TestGeneral_MultAir(t *testing.T) { // none func TestGeneral_ComputeHashOnElements(t *testing.T) { hashEmptyArray := ComputeHashOnElements([]*big.Int{}) - hashEmptyArrayFelt := ComputeHashOnElementsFelt([]*felt.Felt{}) + hashEmptyArrayFelt := PedersenArray([]*felt.Felt{}...) expectedHashEmmptyArray := utils.HexToBN("0x49ee3eba8c1600700ee1b87eb599f16716b0b1022947733551fde4050ca6804") require.Equal(t, hashEmptyArray, expectedHashEmmptyArray, "Hash empty array wrong value.") @@ -315,7 +315,7 @@ func TestGeneral_ComputeHashOnElements(t *testing.T) { } hashFilledArray := ComputeHashOnElements(filledArray) - hashFilledArrayFelt := ComputeHashOnElementsFelt(utils.BigIntArrToFeltArr(filledArray)) + hashFilledArrayFelt := PedersenArray(utils.BigIntArrToFeltArr(filledArray)...) expectedHashFilledArray := utils.HexToBN("0x7b422405da6571242dfc245a43de3b0fe695e7021c148b918cd9cdb462cac59") require.Equal(t, hashFilledArray, expectedHashFilledArray, "Hash filled array wrong value.") diff --git a/hash/hash.go b/hash/hash.go index 9ce5e7b9..0301cb54 100644 --- a/hash/hash.go +++ b/hash/hash.go @@ -41,7 +41,7 @@ func CalculateTransactionHashCommon( chainId, } dataToHash = append(dataToHash, additionalData...) - return curve.ComputeHashOnElementsFelt(dataToHash) + return curve.PedersenArray(dataToHash...) } // ClassHash calculates the hash of a contract class.