Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7b4a194
SHA3-256 added
Matt-Ryley Jan 27, 2022
510b04d
Unit tests now pass
Matt-Ryley Jan 28, 2022
fff5189
SHA3256->SHA3_256
Matt-Ryley Jan 31, 2022
328a9f0
Merge pull request #1 from appliedblockchain/sha3-256
Matt-Ryley Feb 1, 2022
296528e
Merge branch 'algorand:master' into master
Matt-Ryley Feb 1, 2022
17acffe
Update eval.go
Matt-Ryley Feb 15, 2022
5255912
Merged upstream
Matt-Ryley Mar 7, 2022
8050ae4
Added new Opcode to assembler
Matt-Ryley Mar 7, 2022
9d7be44
Ran make to gen spec
Matt-Ryley Mar 11, 2022
64071ba
Removed darwin/arm64 FLAGS
Matt-Ryley Mar 11, 2022
138a02a
Removed darwin/arm64 cgo
Matt-Ryley Mar 11, 2022
ddf44d2
darwin.arm64 reinstalled to batchverifier
Matt-Ryley Mar 11, 2022
54febf5
Removed binary files
Matt-Ryley Mar 11, 2022
5d8d05d
Updated read me
Matt-Ryley Mar 11, 2022
262f0d8
account manager: avoid taking locks for long period of time (#3717)
tsachiherman Mar 7, 2022
e59f713
prefetcher: add Eval vs prefetcher alignment tests (#3729)
tolikzinovyev Mar 9, 2022
62eb294
Tests: E2E testing C2C with ClearStateProgram (#3693)
algoidurovic Mar 9, 2022
0270fc8
ledger: move prefetcher to a new package (#3735)
tolikzinovyev Mar 9, 2022
a5b518a
use ErrorResponse instead of AccountsErrorResponse (#3737)
cce Mar 10, 2022
ea0cfda
prefetcher: ensure the groupTask.incompleteCount is allocated on a 64…
tsachiherman Mar 10, 2022
362491d
AVM: FIDO2 OpCodes (#3514)
tzaffi Mar 10, 2022
fa4a34d
ledger refactoring: test 6M assets/apps per account (#3739)
algonautshant Mar 11, 2022
e08a7da
code styling (#3749)
tsachiherman Mar 11, 2022
db98bbe
REST API: Fix typo in OpenAPI json and yml files (#3741)
nullun Mar 11, 2022
3652724
testing: update Test5MAssetsScenario e2e test (#3750)
tsachiherman Mar 11, 2022
1a0239f
update (#3753)
tsachiherman Mar 11, 2022
b4d36a5
call batchVerificationImpl from OneTimeSignatureVerifier.Verify (#3759)
cce Mar 12, 2022
38f885d
REST API: dryrun scratch slot type fix (#3736)
barnjamin Mar 13, 2022
755756c
move sha3-256 to v7
jannotti Mar 13, 2022
9994dee
spec update
jannotti Mar 14, 2022
c2e3881
Merge remote-tracking branch 'origin/master' into sha3-256
jannotti Mar 14, 2022
e943119
Simplify implementation
jannotti Mar 14, 2022
25d07f3
Matt Ryley, for SHA3-256
jannotti Mar 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions THANKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A big thank you to everyone who has contributed to the `go-algorand` codebase.
- jeapostrophe
- jecassis
- jsign
- Matt-Ryley
- mxmauro
- Olshansk
- qkniep
Expand Down
1 change: 1 addition & 0 deletions data/transactions/logic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ return stack matches the name of the input value.
| `sha256` | SHA256 hash of value A, yields [32]byte |
| `keccak256` | Keccak256 hash of value A, yields [32]byte |
| `sha512_256` | SHA512_256 hash of value A, yields [32]byte |
| `sha3_256` | SHA3_256 hash of value A, yields [32]byte |
| `ed25519verify` | for (data A, signature B, pubkey C) verify the signature of ("ProgData" \|\| program_hash \|\| data) against the pubkey => {0 or 1} |
| `ecdsa_verify v` | for (data A, signature B, C and pubkey D, E) verify the signature of the data against the pubkey => {0 or 1} |
| `ecdsa_pk_recover v` | for (data A, recovery id B, signature C, D) recover a public key |
Expand Down
8 changes: 8 additions & 0 deletions data/transactions/logic/TEAL_opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,14 @@ bitlen interprets arrays as big-endian integers, unlike setbit/getbit

The notation A,B indicates that A and B are interpreted as a uint128 value, with A as the high uint64 and B the low.

## sha3_256

- Opcode: 0x98
- Stack: ..., A: []byte → ..., []byte
- SHA3_256 hash of value A, yields [32]byte
- **Cost**: 130
- Availability: v7

## b+

- Opcode: 0xa0
Expand Down
3 changes: 2 additions & 1 deletion data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,12 @@ pushbytes 0x0123456789abcd
dup
dup
ecdsa_verify Secp256r1
sha3_256
`

const v6Compiled = "2004010002b7a60c26050242420c68656c6c6f20776f726c6421070123456789abcd208dae2087fbba51304eb02b91f656948397a7946390e8cb70fc9ea4d95f92251d047465737400320032013202320380021234292929292b0431003101310231043105310731083109310a310b310c310d310e310f3111311231133114311533000033000133000233000433000533000733000833000933000a33000b33000c33000d33000e33000f3300113300123300133300143300152d2e01022581f8acd19181cf959a1281f8acd19181cf951a81f8acd19181cf1581f8acd191810f082209240a220b230c240d250e230f23102311231223132314181b1c28171615400003290349483403350222231d4a484848482b50512a632223524100034200004322602261222704634848222862482864286548482228246628226723286828692322700048482371004848361c0037001a0031183119311b311d311e311f312023221e312131223123312431253126312731283129312a312b312c312d312e312f447825225314225427042455220824564c4d4b0222382124391c0081e80780046a6f686e2281d00f23241f880003420001892224902291922494249593a0a1a2a3a4a5a6a7a8a9aaabacadae24af3a00003b003c003d816472064e014f012a57000823810858235b235a2359b03139330039b1b200b322c01a23c1001a2323c21a23c3233e233f8120af06002a494905002a49490700b53a03b6b7043cb8033a0c2349c42a9631007300810881088120978101c53a8101c6003a"

const v7Compiled = v6Compiled + "5c005d018120af060180070123456789abcd49490501"
const v7Compiled = v6Compiled + "5c005d018120af060180070123456789abcd4949050198"

var nonsense = map[uint64]string{
1: v1Nonsense,
Expand Down
3 changes: 2 additions & 1 deletion data/transactions/logic/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var opDocByName = map[string]string{
"sha256": "SHA256 hash of value A, yields [32]byte",
"keccak256": "Keccak256 hash of value A, yields [32]byte",
"sha512_256": "SHA512_256 hash of value A, yields [32]byte",
"sha3_256": "SHA3_256 hash of value A, yields [32]byte",
"ed25519verify": "for (data A, signature B, pubkey C) verify the signature of (\"ProgData\" || program_hash || data) against the pubkey => {0 or 1}",
"ecdsa_verify": "for (data A, signature B, C and pubkey D, E) verify the signature of the data against the pubkey => {0 or 1}",
"ecdsa_pk_decompress": "decompress pubkey A into components X, Y",
Expand Down Expand Up @@ -332,7 +333,7 @@ func OpDocExtra(opName string) string {
// here is the order args opcodes are presented, so place related
// opcodes consecutively, even if their opcode values are not.
var OpGroups = map[string][]string{
"Arithmetic": {"sha256", "keccak256", "sha512_256", "ed25519verify", "ecdsa_verify", "ecdsa_pk_recover", "ecdsa_pk_decompress", "+", "-", "/", "*", "<", ">", "<=", ">=", "&&", "||", "shl", "shr", "sqrt", "bitlen", "exp", "==", "!=", "!", "len", "itob", "btoi", "%", "|", "&", "^", "~", "mulw", "addw", "divw", "divmodw", "expw", "getbit", "setbit", "getbyte", "setbyte", "concat"},
"Arithmetic": {"sha256", "keccak256", "sha512_256", "sha3_256", "ed25519verify", "ecdsa_verify", "ecdsa_pk_recover", "ecdsa_pk_decompress", "+", "-", "/", "*", "<", ">", "<=", ">=", "&&", "||", "shl", "shr", "sqrt", "bitlen", "exp", "==", "!=", "!", "len", "itob", "btoi", "%", "|", "&", "^", "~", "mulw", "addw", "divw", "divmodw", "expw", "getbit", "setbit", "getbyte", "setbyte", "concat"},
"Byte Array Manipulation": {"substring", "substring3", "extract", "extract3", "extract_uint16", "extract_uint32", "extract_uint64", "base64_decode", "json_ref"},
"Byte Array Arithmetic": {"b+", "b-", "b/", "b*", "b<", "b>", "b<=", "b>=", "b==", "b!=", "b%", "bsqrt"},
"Byte Array Logic": {"b|", "b&", "b^", "b~"},
Expand Down
7 changes: 7 additions & 0 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,13 @@ func opSHA256(cx *EvalContext) {
cx.stack[last].Bytes = hash[:]
}

// The NIST SHA3-256 is implemented for compatibility with ICON
func opSHA3_256(cx *EvalContext) {
last := len(cx.stack) - 1
hash := sha3.Sum256(cx.stack[last].Bytes)
cx.stack[last].Bytes = hash[:]
}

// The Keccak256 variant of SHA-3 is implemented for compatibility with Ethereum
func opKeccak256(cx *EvalContext) {
last := len(cx.stack) - 1
Expand Down
16 changes: 16 additions & 0 deletions data/transactions/logic/evalCrypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ byte 0xc195eca25a6f4c82bfba0287082ddb0d602ae9230f9cf1f1a40b68f8e2c41567
testAccepts(t, progText, 1)
}

func TestSHA3_256(t *testing.T) {
partitiontest.PartitionTest(t)

t.Parallel()
/*
pip install hashlib
import hashlib
hashlib.sha3_256(b"fnord").hexdigest()
*/
progText := `byte 0x666E6F7264
sha3_256
byte 0xd757297405c5c89f7ceca368ee76c2f1893ee24f654e60032e65fb53b01aae10
==`
testAccepts(t, progText, 7)
}

func TestSHA512_256(t *testing.T) {
partitiontest.PartitionTest(t)

Expand Down
1 change: 1 addition & 0 deletions data/transactions/logic/evalStateful_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ bytec 0
sha256
keccak256
sha512_256
sha3_256
len
intc_0
+
Expand Down
3 changes: 1 addition & 2 deletions data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,7 @@ func BenchmarkBase64Decode(b *testing.B) {
"keccak256",
"sha256",
"sha512_256",
"sha3_256",
"base64_decode StdEncoding",
"base64_decode URLEncoding",
}
Expand Down Expand Up @@ -4937,7 +4938,6 @@ func TestOpJSONRef(t *testing.T) {

for _, s := range testCases {
for v := uint64(2); v < fidoVersion; v++ {
fmt.Printf("%d->%s\n", v, s.source)
expectedErrs := s.previousVersErrors
if fidoVersion <= AssemblerMaxVersion {
for i := range expectedErrs {
Expand Down Expand Up @@ -5127,7 +5127,6 @@ func TestOpJSONRef(t *testing.T) {

for _, s := range failedCases {
for v := uint64(2); v < fidoVersion; v++ {
fmt.Printf("%d->%s\n", v, s.source)
expectedErrs := s.previousVersErrors
if fidoVersion <= AssemblerMaxVersion {
for i := range expectedErrs {
Expand Down
1 change: 1 addition & 0 deletions data/transactions/logic/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ var OpSpecs = []OpSpec{
{0x95, "expw", opExpw, asmDefault, disDefault, twoInts, twoInts, 4, modeAny, costly(10)},
{0x96, "bsqrt", opBytesSqrt, asmDefault, disDefault, oneBytes, oneBytes, 6, modeAny, costly(40)},
{0x97, "divw", opDivw, asmDefault, disDefault, twoInts.plus(oneInt), oneInt, 6, modeAny, opDefault},
{0x98, "sha3_256", opSHA3_256, asmDefault, disDefault, oneBytes, oneBytes, 7, modeAny, costly(130)},

// Byteslice math.
{0xa0, "b+", opBytesPlus, asmDefault, disDefault, twoBytes, oneBytes, 4, modeAny, costly(10)},
Expand Down