Skip to content

Instantly share code, notes, and snippets.

@MichaelEvans
Created January 23, 2014 04:02
Show Gist options
  • Save MichaelEvans/8572618 to your computer and use it in GitHub Desktop.
Save MichaelEvans/8572618 to your computer and use it in GitHub Desktop.
horace.rb
require 'digest/sha1'
class Miner
attr_reader :tree, :parent, :timestamp
def initialize
@tree=`git write-tree`.chomp
@parent=`git rev-parse HEAD`.chomp
@timestamp=12345
end
def gitify_body_with_header(content)
"commit #{content.length}\0#{content}"
end
def prepare_index
user_name = "user-udsg4qtp"
`perl -i -pe 's/(#{user_name}: )(\d+)/$1 . ($2+1)/e' LEDGER.txt`
`grep -q "#{user_name}" LEDGER.txt || echo "#{user_name}: 1" >> LEDGER.txt`
`git add LEDGER.txt`
end
def git_sha(content)
Digest::SHA1.hexdigest(gitify_body_with_header(content))
end
def difficulty
"000001"
end
def generate_body(counter)
body="tree #{tree}
parent #{parent}
author CTF user <[email protected]> #{timestamp} +0000
committer CTF user <[email protected]> #{timestamp} +0000
Give me a Gitcoin
#{counter}
"
end
def run
threads = []
10.times do |i|
threads << Thread.new do
start_time = Time.now
counter = i * 1000000
while true
#puts "Thread #{i} trying with counter #{counter}"
body = generate_body(counter)
sha = git_sha(body)
counter += 1
if sha < difficulty
puts "THREAD #{i} got a hit!"
puts "total time: #{Time.now.to_f - start_time.to_f}"
puts "sha: #{sha}"
puts "counter: #{counter}"
puts "difficulty: #{difficulty}"
File.open("output.txt", "w") do |f|
f.write(body)
end
# prepare_index
# `git hash-object -t commit output.txt -w`
# `git reset --hard #{sha}`
# `git push origin master`
end
if counter > (i+1) * 10000000
break
end
end
end
end
threads.map(&:join)
puts "done"
end
end
Miner.new.run
@MichaelEvans
Copy link
Author

  1. prepare_index from shell
  2. run above
  3. as soon as above completes "git hash-object -t commit output.txt -w"
  4. git reset --hard sha result from 3
  5. git push origin master
  6. ???
  7. profit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment