-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Standardized golang and rust sha256 programs (#160)
- Loading branch information
1 parent
4a96161
commit 0faba3f
Showing
8 changed files
with
114 additions
and
7 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/Cargo.lock | ||
/output | ||
/examples/target | ||
**/.DS_Store |
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,7 @@ | ||
module sha2-go | ||
|
||
go 1.22.5 | ||
|
||
replace github.com/zkMIPS/zkm/go-runtime/zkm_runtime => ../../../go-runtime/zkm_runtime | ||
|
||
require github.com/zkMIPS/zkm/go-runtime/zkm_runtime v0.0.0-20240817102429-2faba0888c02 |
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,50 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"crypto/sha256" | ||
"log" | ||
|
||
"github.com/zkMIPS/zkm/go-runtime/zkm_runtime" | ||
) | ||
|
||
type DataId uint32 | ||
|
||
// use iota to create enum | ||
const ( | ||
TYPE1 DataId = iota | ||
TYPE2 | ||
TYPE3 | ||
) | ||
|
||
type Data struct { | ||
Input1 [10]byte | ||
Input2 uint8 | ||
Input3 int8 | ||
Input4 uint16 | ||
Input5 int16 | ||
Input6 uint32 | ||
Input7 int32 | ||
Input8 uint64 | ||
Input9 int64 | ||
Input10 []byte | ||
Input11 DataId | ||
Input12 string | ||
} | ||
|
||
func main() { | ||
a := zkm_runtime.Read[Data]() | ||
|
||
data := []byte(a.Input12) | ||
hash := sha256.Sum256(data) | ||
|
||
assertEqual(hash[:], a.Input10) | ||
|
||
zkm_runtime.Commit[Data](a) | ||
} | ||
|
||
func assertEqual(a []byte, b []byte) { | ||
if !bytes.Equal(a, b) { | ||
log.Fatal("%x != %x", a, b) | ||
} | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
prover/examples/sha2/Cargo.toml → prover/examples/sha2-rust/Cargo.toml
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,7 +1,7 @@ | ||
[workspace] | ||
[package] | ||
version = "0.1.0" | ||
name = "sha2-bench" | ||
name = "sha2-rust" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
2 changes: 1 addition & 1 deletion
2
prover/examples/sha2/rust-toolchain.toml → ...er/examples/sha2-rust/rust-toolchain.toml
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,4 +1,4 @@ | ||
[toolchain] | ||
channel = "nightly-2023-03-06-x86_64-unknown-linux-gnu" | ||
channel = "nightly-2023-04-06-x86_64-unknown-linux-gnu" | ||
targets = ["mips-unknown-linux-musl"] | ||
profile = "minimal" |
File renamed without changes.
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