kkrt-labs / kakarot-ssj

Kakarot zkEVM - rewrite in the latest version of Cairo
https://www.kakarot.org
MIT License
137 stars 83 forks source link

dev: various optimizations #1010

Closed enitrat closed 1 month ago

enitrat commented 1 month ago

Optimizes ToBytes, FromBytes, to_u64_words

1.

[PASS] utils::traits::integer::tests::u32_test::test_u32_to_bytes_full (gas: ~5)
        steps: 1382
        memory holes: 53
        builtins: (range_check: 125, bitwise: 19)
        syscalls: ()

to

[PASS] utils::traits::integer::tests::u32_test::test_u32_to_bytes_full (gas: ~2)
        steps: 442
        memory holes: 20
        builtins: (range_check: 29, bitwise: 4)
        syscalls: ()

2.

[PASS] utils::traits::integer::tests::u32_test::test_u32_to_le_bytes_full (gas: ~5)
        steps: 1349
        memory holes: 53
        builtins: (range_check: 117, bitwise: 19)
        syscalls: ()

to

[PASS] utils::traits::integer::tests::u32_test::test_u32_to_le_bytes_full (gas: ~2)
        steps: 486
        memory holes: 20
        builtins: (range_check: 34, bitwise: 4)
        syscalls: ()

3.

[PASS] utils::traits::bytes::tests::span_u8_test::test_span_u8_to_64_words_full (gas: ~11)
        steps: 2739
        memory holes: 141
        builtins: (range_check: 274, bitwise: 39)
        syscalls: ()

[PASS] utils::traits::bytes::tests::span_u8_test::test_span_u8_to_64_words_partial (gas: ~8)
        steps: 1965
        memory holes: 114
        builtins: (range_check: 193, bitwise: 27)
        syscalls: ()

to

[PASS] utils::traits::bytes::tests::span_u8_test::test_span_u8_to_64_words_partial (gas: ~8)
        steps: 1972
        memory holes: 81
        builtins: (range_check: 199, bitwise: 27)
        syscalls: ()

[PASS] utils::traits::bytes::tests::span_u8_test::test_span_u8_to_64_words_full (gas: ~12)
        steps: 2847
        memory holes: 146
        builtins: (range_check: 285, bitwise: 39)
        syscalls: ()

This change is Reviewable