-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TODOs] refactor: proof path calculation (#659)
- Loading branch information
1 parent
bfbfcfe
commit f853bcb
Showing
6 changed files
with
121 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package protocol | ||
|
||
import ( | ||
"crypto/sha256" | ||
|
||
"github.com/pokt-network/smt" | ||
) | ||
|
||
// SMT specification used for the proof verification. | ||
var ( | ||
newHasher = sha256.New | ||
SmtSpec smt.TrieSpec | ||
) | ||
|
||
func init() { | ||
// Use a spec that does not prehash values in the smst. This returns a nil value | ||
// hasher for the proof verification in order to avoid hashing the value twice. | ||
SmtSpec = smt.NewTrieSpec( | ||
newHasher(), true, | ||
smt.WithValueHasher(nil), | ||
) | ||
} | ||
|
||
// GetPathForProof computes the path to be used for proof validation by hashing | ||
// the block hash and session id. | ||
func GetPathForProof(blockHash []byte, sessionId string) []byte { | ||
hasher := newHasher() | ||
if _, err := hasher.Write(append(blockHash, []byte(sessionId)...)); err != nil { | ||
panic(err) | ||
} | ||
|
||
return hasher.Sum(nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.