Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions pkg/test/assembly_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func Test_AsmUtil_FillBytes(t *testing.T) {
util.CheckWithFields(t, false, "asm/util/fill_bytes", util.ASM_MAX_PADDING, sc.BLS12_377, sc.KOALABEAR_16)
}

func Test_AsmUtil_FirstByte(t *testing.T) {
util.CheckWithFields(t, false, "asm/util/first_byte", util.ASM_MAX_PADDING, sc.BLS12_377, sc.KOALABEAR_16)
}

func Test_AsmUtil_Log2(t *testing.T) {
util.CheckWithFields(t, false, "asm/util/log2", util.ASM_MAX_PADDING, sc.BLS12_377, sc.KOALABEAR_16)
}
Expand All @@ -49,3 +53,7 @@ func Test_AsmUtil_Min(t *testing.T) {
func Test_AsmUtil_SetByte(t *testing.T) {
util.CheckWithFields(t, false, "asm/util/set_byte", util.ASM_MAX_PADDING, sc.BLS12_377, sc.KOALABEAR_16)
}

func Test_AsmUtil_Signextend(t *testing.T) {
util.CheckWithFields(t, false, "asm/util/signextend", util.ASM_MAX_PADDING, sc.BLS12_377, sc.KOALABEAR_16)
}
1,001 changes: 1,001 additions & 0 deletions testdata/asm/bench/bin.accepts

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions testdata/asm/bench/bin.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
include "evm.zkasm"
include "../util/bit_xoan.zkasm"
include "../util/byte.zkasm"
include "../util/signextend.zkasm"

;; The bin module (BIN) handles the following 6 EVM instructions :
;; 1. AND 2. OR 3. XOR
Expand All @@ -11,13 +12,12 @@ include "../util/byte.zkasm"

fn bin(INST=0x16 u8, ARGUMENT_1 u256, ARGUMENT_2 u256) -> (RES u256) {

;;if INST==EVM_INST_SIGNEXTEND goto signextend_call

if INST==EVM_INST_XOR goto xor_call
if INST==EVM_INST_OR goto or_call
if INST==EVM_INST_AND goto and_call
if INST==EVM_INST_NOT goto not_call
if INST==EVM_INST_BYTE goto byte_call
if INST==EVM_INST_SIGNEXTEND goto signextend_call
fail
var inst u2

Expand All @@ -44,7 +44,17 @@ byte_call:
if c0 != 0 goto exit_0
RES = byte256(ARGUMENT_2, n)
return
signextend_call:
var size u5
var c1 u251
c1, size = ARGUMENT_1
if c1 != 0 goto exit_unchanged
RES = signextend(size, ARGUMENT_2)
return
exit_0:
RES = 0
return
exit_unchanged:
RES = ARGUMENT_2
return
}
6 changes: 6 additions & 0 deletions testdata/asm/util/first_byte.accepts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"first_nonzero_byte": { "word": [255], "res": [31] }}
{"first_nonzero_byte": { "word": [65535], "res": [30] }}
{"first_nonzero_byte": { "word": [4294967295], "res": [28] }}
{"first_nonzero_byte": { "word": [18446744073709551615], "res": [24] }}
{"first_nonzero_byte": { "word": [340282366920938352553754334751646382491], "res": [16] }}
{"first_nonzero_byte": { "word": [115792089237316195423570985008687907853269984665640564039457584007913129639935], "res": [0] }}
64 changes: 64 additions & 0 deletions testdata/asm/util/first_byte.zkasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
;; Find the index of the first non null byte

fn first_nonzero_byte(word=0 u256) -> (res=31 u5) {
var word_hi, word_lo u128
var tmp_res u4
word_hi, word_lo = word
if word_hi != 0 goto high_lab
tmp_res = first_nonzero_byte128(word_lo)
res = 16 + tmp_res
return
high_lab:
res = first_nonzero_byte128(word_hi)
return
}

fn first_nonzero_byte128(word=0 u128) -> (res=15 u4) {
var word_hi, word_lo u64
var tmp_res u3
word_hi, word_lo = word
if word_hi != 0 goto high_lab
tmp_res = first_nonzero_byte64(word_lo)
res = 8 + tmp_res
return
high_lab:
res = first_nonzero_byte64(word_hi)
return
}

fn first_nonzero_byte64(word=0 u64) -> (res=7 u3) {
var word_hi, word_lo u32
var tmp_res u2
word_hi, word_lo = word
if word_hi != 0 goto high_lab
tmp_res = first_nonzero_byte32(word_lo)
res = 4 + tmp_res
return
high_lab:
res = first_nonzero_byte32(word_hi)
return
}

fn first_nonzero_byte32(word=0 u32) -> (res=3 u2) {
var word_hi, word_lo u16
var tmp_res u1
word_hi, word_lo = word
if word_hi != 0 goto high_lab
tmp_res = first_nonzero_byte16(word_lo)
res = 2 + tmp_res
return
high_lab:
res = first_nonzero_byte16(word_hi)
return
}

fn first_nonzero_byte16(word=0 u16) -> (res=1 u1) {
var word_hi, word_lo u8
word_hi, word_lo = word
if word_hi != 0 goto high_lab
res = 1
return
high_lab:
res = 0
return
}
Loading
Loading