protocol

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RelayHasherSize = sha256.Size
	TrieHasherSize  = sha256.Size
	TrieRootSize    = TrieHasherSize + trieRootMetadataSize
)

Variables

View Source
var (
	NewRelayHasher = sha256.New
	NewTrieHasher  = sha256.New
)
View Source
var (
	// BaseRelayDifficultyHashBz is the chosen "highest" (easiest) target hash, which
	// corresponds to the lowest possible difficulty.
	//
	// It effectively normalizes the difficulty number (which is returned by GetDifficultyFromHash)
	// by defining the hash which corresponds to the base difficulty.
	//
	// When this is the difficulty of a particular service, all relays are reward / volume applicable.
	//
	// Bitcoin uses a similar concept, where the target hash is defined as the hash:
	// - https://bitcoin.stackexchange.com/questions/107976/bitcoin-difficulty-why-leading-0s
	// - https://bitcoin.stackexchange.com/questions/121920/is-it-always-possible-to-find-a-number-whose-hash-starts-with-a-certain-number-o
	BaseRelayDifficultyHashBz, _ = hex.DecodeString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
)
View Source
var (
	SmtSpec smt.TrieSpec
)

SMT specification used for the proof verification.

Functions

func GetDifficultyFromHash added in v0.0.5

func GetDifficultyFromHash(hashBz [RelayHasherSize]byte) int64

GetDifficultyFromHash returns the "difficulty" of the given hash, with respect to the "highest" (easiest) target hash, BaseRelayDifficultyHash. The resultant value is not used for any business logic but is simplify there to have a human-readable version of the hash. TODO_MAINNET: Can this cause an integer overflow?

func GetPathForProof added in v0.0.4

func GetPathForProof(blockHash []byte, sessionId string) []byte

GetPathForProof computes the path to be used for proof validation by hashing the block hash and session id.

func GetRelayHashFromBytes added in v0.0.5

func GetRelayHashFromBytes(relayBz []byte) (hash [RelayHasherSize]byte)

GetRelayHashFromBytes returns the hash of the relay (full, request or response) bytes. It is used as helper in the case that the relay is already marshaled and centralizes the hasher used.

func IsRelayVolumeApplicable added in v0.0.5

func IsRelayVolumeApplicable(relayHash, targetHash []byte) bool

IsRelayVolumeApplicable returns true if the relay IS reward / volume applicable. A relay is reward / volume applicable IFF its hash is less than the target hash.

  • relayHash is the hash of the relay to be checked.
  • targetHash is the hash of the relay difficulty target for a particular service.

TODO_MAINNET: Devise a test that tries to attack the network and ensure that there is sufficient telemetry.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL