Skip to content

Commit

Permalink
wip : sierra hashing logic broken
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Oct 2, 2023
1 parent 7def09e commit e7d0c58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion artifacts/hello_starknet_compiled.sierra.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,5 +358,5 @@
"L1_HANDLER": [],
"CONSTRUCTOR": []
},
"abi": "[{\"type\":\"function\",\"name\":\"increase_balance\",\"inputs\":[{\"name\":\"amount\",\"type\":\"core::felt252\"}],\"outputs\":[],\"state_mutability\":\"external\"},{\"type\":\"function\",\"name\":\"get_balance\",\"inputs\":[],\"outputs\":[{\"type\":\"core::felt252\"}],\"state_mutability\":\"view\"},{\"type\":\"event\",\"name\":\"hello_starknet::hello_starknet::hello_starknet::Event\",\"kind\":\"enum\",\"variants\":[]}]"
"abi": "[{\"type\": \"function\", \"name\": \"increase_balance\", \"inputs\": [{\"name\": \"amount\", \"type\": \"core::felt252\"}], \"outputs\": [], \"state_mutability\": \"external\"}, {\"type\": \"function\", \"name\": \"get_balance\", \"inputs\": [], \"outputs\": [{\"type\": \"core::felt252\"}], \"state_mutability\": \"view\"}, {\"type\": \"event\", \"name\": \"hello_starknet::hello_starknet::hello_starknet::Event\", \"kind\": \"enum\", \"variants\": []}]"
}
13 changes: 12 additions & 1 deletion hash/hash.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package hash

import (
"fmt"

"github.com/NethermindEth/juno/core/felt"
starknetgo "github.com/NethermindEth/starknet.go"
newcontract "github.com/NethermindEth/starknet.go/newcontracts"
Expand Down Expand Up @@ -47,7 +49,8 @@ func CalculateTransactionHashCommon(
}

func ClassHash(contract rpc.ContractClass) (*felt.Felt, error) {
//https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/class-hash/
// https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/class-hash/
// https://github.com/starkware-libs/cairo-lang/blob/7712b21fc3b1cb02321a58d0c0579f5370147a8b/src/starkware/starknet/core/os/contracts.cairo#L47

Version := "CONTRACT_CLASS_V" + contract.ContractClassVersion
ContractClassVersionHash := new(felt.Felt).SetBytes([]byte(Version))
Expand All @@ -64,6 +67,7 @@ func ClassHash(contract rpc.ContractClass) (*felt.Felt, error) {
if err != nil {
return nil, err
}
// The ABI Bytes seem to match, but the hash does not
ABI := new(felt.Felt).SetBytes([]byte(contract.ABI))
ABIHash, err := ComputeHashOnElementsFelt([]*felt.Felt{ABI})
if err != nil {
Expand All @@ -74,6 +78,13 @@ func ClassHash(contract rpc.ContractClass) (*felt.Felt, error) {
return nil, err
}

fmt.Println("ContractClassVersionHash", ContractClassVersionHash) // Correct
fmt.Println("ExternalHash", ExternalHash) // Incorrect
fmt.Println("L1HandleHash", L1HandleHash) // Incorrect
fmt.Println("ConstructorHash", ConstructorHash) // Incorrect
fmt.Println("newABIHash", ABIHash) // Incorrect
fmt.Println("SierraProgamHash", SierraProgamHash) // Incorrect

// https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/transactions/#deploy_account_hash_calculation
return ComputeHashOnElementsFelt(
[]*felt.Felt{
Expand Down

0 comments on commit e7d0c58

Please sign in to comment.