Skip to content

Instantly share code, notes, and snippets.

@akamajoris
Created August 27, 2018 08:45
Show Gist options
  • Save akamajoris/252d9154fdb4ccce0ca166329f6b6ec9 to your computer and use it in GitHub Desktop.
Save akamajoris/252d9154fdb4ccce0ca166329f6b6ec9 to your computer and use it in GitHub Desktop.
Etherum methods collision finder
package main
import (
"encoding/hex"
"fmt"
"log"
"os"
"github.com/ethereum/go-ethereum/crypto/sha3"
)
var target = "dc6dd152" // playerRollDice(uint256)
var postfix = `(uint256)`
func main() {
var c = 0
for i := 5; i <= 7; i++ {
for combination := range generateCombinations("0123456789abcdefghijklmnopqrstuvwxyz", i) {
c++
if combination[0] == '0' || combination[0] == '1' || combination[0] == '2' || combination[0] == '3' || combination[0] == '4' || combination[0] == '5' || combination[0] == '6' || combination[0] == '7' || combination[0] == '8' || combination[0] == '9' {
continue
}
if getHash(combination) == target {
log.Println("Found:", string(combination)+postfix)
os.Exit(0)
}
if c%1000000 == 0 {
log.Println(c)
}
}
log.Println("Finished n", i)
}
fmt.Println("Done!")
}
func getHash(src string) string {
hash := sha3.NewKeccak256()
var buf []byte
hash.Write([]byte(src + postfix))
buf = hash.Sum(buf)
return hex.EncodeToString(buf)[:8]
}
func generateCombinations(alphabet string, length int) <-chan string {
c := make(chan string)
go func(c chan string) {
defer close(c)
addLetter(c, "", alphabet, length)
}(c)
return c
}
func addLetter(c chan string, combo string, alphabet string, length int) {
if length <= 0 {
return
}
var newCombo string
for _, ch := range alphabet {
newCombo = combo + string(ch)
c <- newCombo
addLetter(c, newCombo, alphabet, length-1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment