diff --git a/account/account.go b/account/account.go index 16067a47..1a28da0f 100644 --- a/account/account.go +++ b/account/account.go @@ -203,8 +203,6 @@ func (account *Account) TransactionHashDeployAccount(tx rpc.DeployAccountType, c if txn.Version == "" || txn.ResourceBounds == (rpc.ResourceBoundsMapping{}) || txn.Nonce == nil || txn.PayMasterData == nil { return nil, ErrNotAllParametersSet } - calldata := []*felt.Felt{txn.ClassHash, txn.ContractAddressSalt} - calldata = append(calldata, txn.ConstructorCalldata...) //nolint:all txnVersionFelt, err := new(felt.Felt).SetString(string(txn.Version)) if err != nil { diff --git a/contracts/contracts.go b/contracts/contracts.go index 1150f7aa..e8c719c2 100644 --- a/contracts/contracts.go +++ b/contracts/contracts.go @@ -61,16 +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 { - - feltArr := []*felt.Felt{ + return curve.ComputeHashOnElementsFelt([]*felt.Felt{ PREFIX_CONTRACT_ADDRESS, deployerAddress, salt, classHash, - } - - constructorCallDataHash := curve.ComputeHashOnElementsFelt(constructorCalldata) - feltArr = append(feltArr, constructorCallDataHash) - - return curve.ComputeHashOnElementsFelt(feltArr) + curve.ComputeHashOnElementsFelt(constructorCalldata), + }) } diff --git a/curve/curve.go b/curve/curve.go index d03131f6..a86ccee4 100644 --- a/curve/curve.go +++ b/curve/curve.go @@ -521,12 +521,12 @@ func (sc StarkCurve) SignFelt(msgHash, privKey *felt.Felt) (*felt.Felt, *felt.Fe return xFelt, yFelt, nil } -// HashElements calculates the hash of a list of elements using a golang Pedersen Hash. +// HashPedersenElements calculates the hash of a list of elements using a golang Pedersen Hash. // Parameters: // - elems: slice of big.Int pointers to be hashed // Returns: // - hash: The hash of the list of elements -func HashElements(elems []*big.Int) (hash *big.Int) { +func HashPedersenElements(elems []*big.Int) (hash *big.Int) { feltArr := utils.BigIntArrToFeltArr(elems) if len(elems) == 0 { feltArr = append(feltArr, new(felt.Felt)) @@ -543,7 +543,7 @@ func HashElements(elems []*big.Int) (hash *big.Int) { // ComputeHashOnElements computes the hash on the given elements using a golang Pedersen Hash implementation. // -// The function appends the length of `elems` to the slice and then calls the `HashElements` method +// The function appends the length of `elems` to the slice and then calls the `HashPedersenElements` method // passing in `elems` as an argument. The resulting hash is returned. // // Parameters: @@ -552,7 +552,7 @@ func HashElements(elems []*big.Int) (hash *big.Int) { // - hash: The hash of the list of elements func ComputeHashOnElements(elems []*big.Int) (hash *big.Int) { elems = append(elems, big.NewInt(int64(len(elems)))) - return HashElements(elems) + return HashPedersenElements(elems) } // ComputeHashOnElementsFelt computes the hash on elements of a Felt array. diff --git a/curve/curve_test.go b/curve/curve_test.go index db7a313d..5e5810ac 100644 --- a/curve/curve_test.go +++ b/curve/curve_test.go @@ -330,7 +330,7 @@ func TestGeneral_ComputeHashOnElements(t *testing.T) { // // none func TestGeneral_HashAndSign(t *testing.T) { - hashy := HashElements([]*big.Int{ + hashy := HashPedersenElements([]*big.Int{ big.NewInt(1953658213), big.NewInt(126947999705460), big.NewInt(1953658213), diff --git a/merkle/merkle.go b/merkle/merkle.go index c1c32940..58053981 100644 --- a/merkle/merkle.go +++ b/merkle/merkle.go @@ -27,8 +27,7 @@ func NewFixedSizeMerkleTree(leaves ...*big.Int) *FixedSizeMerkleTree { Leaves: leaves, Branches: [][]*big.Int{}, } - root := mt.build(leaves) - mt.Root = root + mt.Root = mt.build(leaves) return mt } @@ -41,9 +40,9 @@ func NewFixedSizeMerkleTree(leaves ...*big.Int) *FixedSizeMerkleTree { // - *big.Int: the Merkle hash of the two big integers func MerkleHash(x, y *big.Int) *big.Int { if x.Cmp(y) <= 0 { - return curve.HashElements([]*big.Int{x, y}) + return curve.HashPedersenElements([]*big.Int{x, y}) } - return curve.HashElements([]*big.Int{y, x}) + return curve.HashPedersenElements([]*big.Int{y, x}) } // build recursively constructs a Merkle tree from the given leaves. diff --git a/typed/typed.go b/typed/typed.go index 54771223..f1b89915 100644 --- a/typed/typed.go +++ b/typed/typed.go @@ -141,8 +141,8 @@ func (td TypedData) GetMessageHash(account *big.Int, msg TypedMessage) (hash *bi msgEnc := td.GetTypedMessageHash(td.PrimaryType, msg) elements = append(elements, msgEnc) - hash = curve.ComputeHashOnElements(elements) - return hash + + return curve.ComputeHashOnElements(elements) } // GetTypedMessageHash calculates the hash of a typed message using the provided StarkCurve. @@ -171,12 +171,11 @@ func (td TypedData) GetTypedMessageHash(inType string, msg TypedMessage) (hash * innerElements = append(innerElements, fmtDefinitions...) innerElements = append(innerElements, big.NewInt(int64(len(innerElements)))) - innerHash := curve.HashElements(innerElements) + innerHash := curve.HashPedersenElements(innerElements) elements = append(elements, innerHash) } - hash = curve.ComputeHashOnElements(elements) - return hash + return curve.ComputeHashOnElements(elements) } // GetTypeHash returns the hash of the given type. @@ -191,8 +190,7 @@ func (td TypedData) GetTypeHash(inType string) (ret *big.Int, err error) { if err != nil { return ret, err } - sel := utils.GetSelectorFromName(enc) - return sel, nil + return utils.GetSelectorFromName(enc), nil } // EncodeType encodes the given inType using the TypedData struct. diff --git a/utils/keccak.go b/utils/keccak.go index 4426a1bd..1133df96 100644 --- a/utils/keccak.go +++ b/utils/keccak.go @@ -82,9 +82,8 @@ func HexToBN(hexString string) *big.Int { // - *big.Int: the converted array func HexArrToBNArr(hexArr []string) []*big.Int { bigNumArr := make([]*big.Int, len(hexArr)) - for i, e := range hexArr { - bigNum := HexToBN(e) - bigNumArr[i] = bigNum + for i, hexStr := range hexArr { + bigNumArr[i] = HexToBN(hexStr) } return bigNumArr }