-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduced footprint of exported symbols (#8)
* chore: gitignore coverage artifacts and `experimental/` directory * chore: reduce exported-symbol footprint * chore: rename test to be more precise
- Loading branch information
1 parent
2a33450
commit ad051a8
Showing
5 changed files
with
90 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# IDEs | ||
workspace.code-workspace | ||
|
||
workspace.code-workspace | ||
# Scratchpad | ||
experimental/** | ||
|
||
# Coverage | ||
cover.out | ||
lcov.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Package types defines types used by the specialops package, which is intended | ||
// to be dot-imported so requires a minimal footprint of exported symbols. | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/core/vm" | ||
) | ||
|
||
// A Bytecoder returns raw EVM bytecode. If the returned bytecode is the | ||
// concatenation of multiple Bytecoder outputs, the type MUST also implement | ||
// BytecodeHolder. | ||
type Bytecoder interface { | ||
Bytecode() ([]byte, error) | ||
} | ||
|
||
// A BytecodeHolder is a concatenation of Bytecoders. | ||
type BytecodeHolder interface { | ||
Bytecoder | ||
Bytecoders() []Bytecoder | ||
} | ||
|
||
// A StackPusher returns [1,32] bytes to be pushed to the stack. | ||
type StackPusher interface { | ||
ToPush() []byte | ||
} | ||
|
||
// BytecoderFromStackPusher returns a Bytecoder that calls s.ToPush() and | ||
// prepends the appropriate PUSH<N> opcode to the returned bytecode. | ||
func BytecoderFromStackPusher(s StackPusher) Bytecoder { | ||
return pusher{s} | ||
} | ||
|
||
type pusher struct { | ||
StackPusher | ||
} | ||
|
||
func (p pusher) Bytecode() ([]byte, error) { | ||
buf := p.ToPush() | ||
n := len(buf) | ||
if n == 0 || n > 32 { | ||
return nil, fmt.Errorf("len(%T.ToPush()) == %d must be in [1,32]", p.StackPusher, n) | ||
} | ||
|
||
size := n | ||
for _, b := range buf { | ||
if b == 0 { | ||
size-- | ||
} else { | ||
break | ||
} | ||
} | ||
if size == 0 { | ||
return []byte{byte(vm.PUSH0)}, nil | ||
} | ||
|
||
return append( | ||
// PUSH0 to PUSH32 are contiguous, so we can perform arithmetic on them. | ||
[]byte{byte(vm.PUSH0 + vm.OpCode(size))}, | ||
buf[n-size:]..., | ||
), nil | ||
} |