-
Notifications
You must be signed in to change notification settings - Fork 0
/
basel.go
60 lines (50 loc) · 857 Bytes
/
basel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package pidentities
import (
. "github.com/solidifylabs/specops" //lint:ignore ST1001 SpecOps DSL is designed to be dot-imported
"github.com/solidifylabs/specops/stack"
)
// Basel implements the Basel problem.
func Basel() Code {
return convert(basel)
}
func basel() (Code, uint8) {
const bits = 126
const (
one = Inverted(DUP1) + iota
bigSix
n
sum
)
const (
_ = Inverted(SWAP1) + iota
_
swapN
)
return Code{
PUSH(1),
Fn(SHL, PUSH(bits), PUSH(6)),
one, // n
PUSH0, // sum
JUMPDEST("loop"),
stack.SetDepth(4),
Fn(ADD,
Fn(DIV,
bigSix,
Fn(MUL, n, n),
),
// sum
),
Fn(JUMPI,
PUSH("loop"),
Fn(GT,
PUSH(0x071040), // ~25M gas
Fn(swapN,
Fn(ADD, n, one),
),
),
),
stack.Transform(4)(0),
Fn(SHL, PUSH(bits)), // sqrt will remove the precision
sqrt(),
}, bits
}