-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #917 from nspcc-dev/feature/crypto
vm: remove crypto-related opcodes
- Loading branch information
Showing
13 changed files
with
90 additions
and
110 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
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,15 @@ | ||
package crypto | ||
|
||
import ( | ||
"github.com/nspcc-dev/neo-go/pkg/core/interop" | ||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash" | ||
"github.com/nspcc-dev/neo-go/pkg/vm" | ||
) | ||
|
||
// Sha256 returns sha256 hash of the data. | ||
func Sha256(ic *interop.Context, v *vm.VM) error { | ||
msg := getMessage(ic, v.Estack().Pop().Item()) | ||
h := hash.Sha256(msg).BytesBE() | ||
v.Estack().PushVal(h) | ||
return nil | ||
} |
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,30 @@ | ||
package crypto | ||
|
||
import ( | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/nspcc-dev/neo-go/pkg/core/interop" | ||
"github.com/nspcc-dev/neo-go/pkg/io" | ||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" | ||
"github.com/nspcc-dev/neo-go/pkg/vm" | ||
"github.com/nspcc-dev/neo-go/pkg/vm/emit" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSHA256(t *testing.T) { | ||
// 0x0100 hashes to 47dc540c94ceb704a23875c11273e16bb0b8a87aed84de911f2133568115f254 | ||
res := "47dc540c94ceb704a23875c11273e16bb0b8a87aed84de911f2133568115f254" | ||
buf := io.NewBufBinWriter() | ||
emit.Bytes(buf.BinWriter, []byte{1, 0}) | ||
emit.Syscall(buf.BinWriter, "Neo.Crypto.SHA256") | ||
prog := buf.Bytes() | ||
v := vm.New() | ||
ic := &interop.Context{Trigger: trigger.Verification} | ||
v.RegisterInteropGetter(GetInterop(ic)) | ||
v.Load(prog) | ||
require.NoError(t, v.Run()) | ||
assert.Equal(t, 1, v.Estack().Len()) | ||
assert.Equal(t, res, hex.EncodeToString(v.Estack().Pop().Bytes())) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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