Skip to content

Instantly share code, notes, and snippets.

@yaronvel
Last active October 18, 2016 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaronvel/876c1d359a1532d76eb14cba3ebabb21 to your computer and use it in GitHub Desktop.
Save yaronvel/876c1d359a1532d76eb14cba3ebabb21 to your computer and use it in GitHub Desktop.
EXP opcode pricing

I suspect that EXP operation (opcode 0x0a) is either under-priced or inefficiently implemented in geth. The evm program 6100005b60037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9800a509061000101806127101190915700 computes EXP(ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9,ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9) for 10000 times. It consumes around 3M gas (see testnet tx: https://testnet.etherscan.io/tx/0x5322ba8426c957a2abafec0a4473baf703d7bea221c17c0faa213889e22db034), so it could fit in a single block. However, on my pc it takes 3.5 seconds to excecute (see experiment.go).

If my calculation are current, then a miner could benifit by continiously submitting such tx (costs around 1 USD per tx) and gain 3.5 seconds advantage over the other miners. Since the block interval is around 15 seconds and the block reward is around 50 USD, then a miner with 6% of the total network mining power could benifit from such an attack.

Some remarks: (1) On parity client it only takes 0.3 seconds

(2) I don't know much about go, so maybe I am missing some optimization flags

(3) EXP(fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff,fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) only takes a third of that time.

package main
import (
"fmt"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm/runtime"
)
func main() {
program := "6100005b60037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9800a509061000101806127101190915700"
start := time.Now()
runtime.Execute(common.Hex2Bytes(program), nil, nil)
elapsed := time.Since(start)
fmt.Printf("experiment took %s", elapsed)
}
// on my pc the result is 3.5 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment