Skip to content

Commit

Permalink
generator: add more basic strategies (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed May 16, 2024
1 parent 621abf8 commit 7828990
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions generator/basic_strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ var basicStrategies = []Strategy{
new(memStorageGenerator),
new(mstoreGenerator),
new(sstoreGenerator),
new(tstoreGenerator),
new(returnDataGenerator),
new(returnGenerator),
new(pushGenerator),
new(hashAndStoreGenerator),
new(mloadGenerator),
new(sloadGenerator),
new(tloadGenerator),
new(blobhashGenerator),
}

type opcodeGenerator struct{}
Expand Down Expand Up @@ -95,6 +100,21 @@ func (*sstoreGenerator) Importance() int {
return 3
}

type tstoreGenerator struct{}

func (*tstoreGenerator) Execute(env Environment) {
// Store data in storage
var (
data = make([]byte, env.f.Byte()%32)
slot = uint32(env.f.MemInt().Uint64())
)
env.p.Tstore(slot, data)
}

func (*tstoreGenerator) Importance() int {
return 3
}

type returnDataGenerator struct{}

func (*returnDataGenerator) Execute(env Environment) {
Expand Down Expand Up @@ -149,3 +169,51 @@ func (*hashAndStoreGenerator) Execute(env Environment) {
func (*hashAndStoreGenerator) Importance() int {
return 2
}

type mloadGenerator struct{}

func (*mloadGenerator) Execute(env Environment) {
offset := uint32(env.f.MemInt().Uint64())
env.p.Push(offset)
env.p.Op(ops.MLOAD)
}

func (*mloadGenerator) Importance() int {
return 1
}

type sloadGenerator struct{}

func (*sloadGenerator) Execute(env Environment) {
offset := uint32(env.f.MemInt().Uint64())
env.p.Push(offset)
env.p.Op(ops.SLOAD)
}

func (*sloadGenerator) Importance() int {
return 1
}

type tloadGenerator struct{}

func (*tloadGenerator) Execute(env Environment) {
offset := uint32(env.f.MemInt().Uint64())
env.p.Push(offset)
env.p.Op(ops.TLOAD)
}

func (*tloadGenerator) Importance() int {
return 1
}

type blobhashGenerator struct{}

func (*blobhashGenerator) Execute(env Environment) {
offset := uint32(env.f.MemInt().Uint64())
env.p.Push(offset)
env.p.Op(ops.BLOBHASH)
}

func (*blobhashGenerator) Importance() int {
return 1
}

0 comments on commit 7828990

Please sign in to comment.