Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
refactor: rename concrete/wasm/bin and tinygo/std (ethereum-optimism#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
therealbytes committed Sep 2, 2023
1 parent 69dff05 commit afadf59
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion concrete/concrete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/stretchr/testify/require"
)

//go:embed wasm/bin/typical.wasm
//go:embed wasm/testdata/typical.wasm
var typicalWasm []byte

var implementations = []struct {
Expand Down
26 changes: 13 additions & 13 deletions concrete/lib/precompiles/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
cc_api "github.com/ethereum/go-ethereum/concrete/api"
"github.com/ethereum/go-ethereum/concrete/crypto"
"github.com/ethereum/go-ethereum/concrete/lib"
"github.com/ethereum/go-ethereum/tinygo/std"
tinygo_lib "github.com/ethereum/go-ethereum/tinygo/lib"
)

// A precompiled used for benchmarking TinyGo WASM.
Expand All @@ -32,44 +32,44 @@ type BenchmarkPrecompile struct {

func (pc *BenchmarkPrecompile) Run(api cc_api.API, input []byte) ([]byte, error) {

runStart := std.Now()
runStart := tinygo_lib.Now()

var runs int
var startTime time.Time
var endTime time.Time
var timeNs int64

hash := std.Keccak256(input)
hash := tinygo_lib.Keccak256(input)

// std.Keccak256Hash
// tinygo_lib.Keccak256Hash

runs = 10000
startTime = std.Now()
startTime = tinygo_lib.Now()

for i := 0; i < runs; i++ {
hash = std.Keccak256(hash)
hash = tinygo_lib.Keccak256(hash)
}

endTime = std.Now()
endTime = tinygo_lib.Now()
timeNs = endTime.Sub(startTime).Nanoseconds()
std.Print("std.Keccak256Hash", runs, "op", timeNs, "ns", int(timeNs)/runs, "ns/op")
tinygo_lib.Print("tinygo_lib.Keccak256Hash", runs, "op", timeNs, "ns", int(timeNs)/runs, "ns/op")

// crypto.Keccak256Hash

runs = 10000
startTime = std.Now()
startTime = tinygo_lib.Now()

for i := 0; i < runs; i++ {
hash = crypto.Keccak256(hash)
}

endTime = std.Now()
endTime = tinygo_lib.Now()
timeNs = endTime.Sub(startTime).Nanoseconds()
std.Print("crypto.Keccak256Hash", runs, "op", timeNs, "ns", int(timeNs)/runs, "ns/op")
tinygo_lib.Print("crypto.Keccak256Hash", runs, "op", timeNs, "ns", int(timeNs)/runs, "ns/op")

runEnd := std.Now()
runEnd := tinygo_lib.Now()

std.Print("BenchmarkPrecompile.Run", runEnd.Sub(runStart).Microseconds(), "μs")
tinygo_lib.Print("BenchmarkPrecompile.Run", runEnd.Sub(runStart).Microseconds(), "μs")

return nil, nil
}
8 changes: 4 additions & 4 deletions concrete/lib/precompiles/typical.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import (
cc_api "github.com/ethereum/go-ethereum/concrete/api"
"github.com/ethereum/go-ethereum/concrete/crypto"
"github.com/ethereum/go-ethereum/concrete/lib"
"github.com/ethereum/go-ethereum/tinygo/std"
tinygo_lib "github.com/ethereum/go-ethereum/tinygo/lib"
)

// A precompile used for testing.

// We use std.Keccak256Hash instead of crypto.Keccak256Hash because the latter
// We use tinygo_lib.Keccak256Hash instead of crypto.Keccak256Hash because the latter
// may not compile in tinygo as may depend on a host function.
var (
runCounterKey = std.Keccak256Hash([]byte("typical.counter.0"))
hashSetKey = std.Keccak256Hash([]byte("typical.set.0"))
runCounterKey = tinygo_lib.Keccak256Hash([]byte("typical.counter.0"))
hashSetKey = tinygo_lib.Keccak256Hash([]byte("typical.set.0"))
)

type TypicalPrecompile struct{}
Expand Down
2 changes: 1 addition & 1 deletion concrete/wasm/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestPutGetReturnWithError(t *testing.T) {
testMemoryPutGetReturnWithError(t, memory)
}

//go:embed bin/blank.wasm
//go:embed testdata/blank.wasm
var blankCode []byte

func newTestMemory() (bridge.Memory, bridge.Allocator) {
Expand Down
4 changes: 2 additions & 2 deletions concrete/wasm/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (
"github.com/stretchr/testify/require"
)

//go:embed bin/typical.wasm
//go:embed testdata/typical.wasm
var typicalCode []byte

//go:embed bin/benchmark.wasm
//go:embed testdata/benchmark.wasm
var benchmarkCode []byte

var typicalImplementations = []struct {
Expand Down
2 changes: 1 addition & 1 deletion tinygo/std/lib_go.go → tinygo/lib/lib_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

//go:build !tinygo

package std
package lib

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tinygo/std/lib_tinygo.go → tinygo/lib/lib_tinygo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

//go:build tinygo

package std
package lib

import (
"fmt"
Expand Down

0 comments on commit afadf59

Please sign in to comment.