Skip to content

Commit

Permalink
Remove ComputeHashOnElementsFelt func
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed Aug 15, 2024
1 parent f9119ce commit 12a9e79
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
10 changes: 5 additions & 5 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
)
}
11 changes: 0 additions & 11 deletions curve/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions curve/curve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.")
Expand All @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 12a9e79

Please sign in to comment.