cchecksum 0.4.0__cp312-cp312-musllinux_1_2_i686.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- benchmarks/__init__.py +0 -0
- benchmarks/data.py +70 -0
- benchmarks/test_checksum_benchmarks.py +23 -0
- cchecksum/__init__.py +15 -0
- cchecksum/_checksum.c +32263 -0
- cchecksum/_checksum.cpython-312-i386-linux-musl.so +0 -0
- cchecksum/_checksum.pyi +72 -0
- cchecksum/_checksum.pyx +549 -0
- cchecksum/keccak.c +127 -0
- cchecksum/keccak.h +8 -0
- cchecksum/monkey_patch.py +47 -0
- cchecksum/py.typed +0 -0
- cchecksum-0.4.0.dist-info/METADATA +50 -0
- cchecksum-0.4.0.dist-info/RECORD +17 -0
- cchecksum-0.4.0.dist-info/WHEEL +5 -0
- cchecksum-0.4.0.dist-info/licenses/LICENSE +21 -0
- cchecksum-0.4.0.dist-info/top_level.txt +2 -0
cchecksum/keccak.c
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#include "keccak.h"
|
|
2
|
+
|
|
3
|
+
#include <stdint.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
#define KECCAKF_ROUNDS 24
|
|
7
|
+
|
|
8
|
+
static const uint64_t keccakf_rndc[KECCAKF_ROUNDS] = {
|
|
9
|
+
0x0000000000000001ULL, 0x0000000000008082ULL,
|
|
10
|
+
0x800000000000808aULL, 0x8000000080008000ULL,
|
|
11
|
+
0x000000000000808bULL, 0x0000000080000001ULL,
|
|
12
|
+
0x8000000080008081ULL, 0x8000000000008009ULL,
|
|
13
|
+
0x000000000000008aULL, 0x0000000000000088ULL,
|
|
14
|
+
0x0000000080008009ULL, 0x000000008000000aULL,
|
|
15
|
+
0x000000008000808bULL, 0x800000000000008bULL,
|
|
16
|
+
0x8000000000008089ULL, 0x8000000000008003ULL,
|
|
17
|
+
0x8000000000008002ULL, 0x8000000000000080ULL,
|
|
18
|
+
0x000000000000800aULL, 0x800000008000000aULL,
|
|
19
|
+
0x8000000080008081ULL, 0x8000000000008080ULL,
|
|
20
|
+
0x0000000080000001ULL, 0x8000000080008008ULL
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
static const int keccakf_rotc[KECCAKF_ROUNDS] = {
|
|
24
|
+
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
|
|
25
|
+
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
static const int keccakf_piln[KECCAKF_ROUNDS] = {
|
|
29
|
+
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
|
|
30
|
+
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
static inline uint64_t rotl64(uint64_t x, int s) {
|
|
34
|
+
return (x << s) | (x >> (64 - s));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static inline uint64_t load64(const unsigned char* x) {
|
|
38
|
+
return ((uint64_t)x[0]) | ((uint64_t)x[1] << 8) | ((uint64_t)x[2] << 16) |
|
|
39
|
+
((uint64_t)x[3] << 24) | ((uint64_t)x[4] << 32) |
|
|
40
|
+
((uint64_t)x[5] << 40) | ((uint64_t)x[6] << 48) |
|
|
41
|
+
((uint64_t)x[7] << 56);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static inline void store64(unsigned char* x, uint64_t u) {
|
|
45
|
+
x[0] = (unsigned char)(u & 0xFF);
|
|
46
|
+
x[1] = (unsigned char)((u >> 8) & 0xFF);
|
|
47
|
+
x[2] = (unsigned char)((u >> 16) & 0xFF);
|
|
48
|
+
x[3] = (unsigned char)((u >> 24) & 0xFF);
|
|
49
|
+
x[4] = (unsigned char)((u >> 32) & 0xFF);
|
|
50
|
+
x[5] = (unsigned char)((u >> 40) & 0xFF);
|
|
51
|
+
x[6] = (unsigned char)((u >> 48) & 0xFF);
|
|
52
|
+
x[7] = (unsigned char)((u >> 56) & 0xFF);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static void keccakf(uint64_t st[25]) {
|
|
56
|
+
int i;
|
|
57
|
+
int j;
|
|
58
|
+
int round;
|
|
59
|
+
uint64_t t;
|
|
60
|
+
uint64_t bc[5];
|
|
61
|
+
|
|
62
|
+
for (round = 0; round < KECCAKF_ROUNDS; round++) {
|
|
63
|
+
for (i = 0; i < 5; i++) {
|
|
64
|
+
bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (i = 0; i < 5; i++) {
|
|
68
|
+
t = bc[(i + 4) % 5] ^ rotl64(bc[(i + 1) % 5], 1);
|
|
69
|
+
for (j = 0; j < 25; j += 5) {
|
|
70
|
+
st[j + i] ^= t;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
t = st[1];
|
|
75
|
+
for (i = 0; i < KECCAKF_ROUNDS; i++) {
|
|
76
|
+
j = keccakf_piln[i];
|
|
77
|
+
bc[0] = st[j];
|
|
78
|
+
st[j] = rotl64(t, keccakf_rotc[i]);
|
|
79
|
+
t = bc[0];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (j = 0; j < 25; j += 5) {
|
|
83
|
+
for (i = 0; i < 5; i++) {
|
|
84
|
+
bc[i] = st[j + i];
|
|
85
|
+
}
|
|
86
|
+
for (i = 0; i < 5; i++) {
|
|
87
|
+
st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
st[0] ^= keccakf_rndc[round];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
void keccak_256(const unsigned char* data, size_t len, unsigned char* out) {
|
|
96
|
+
uint64_t st[25];
|
|
97
|
+
unsigned char temp[136];
|
|
98
|
+
size_t i;
|
|
99
|
+
const size_t rate = 136;
|
|
100
|
+
|
|
101
|
+
memset(st, 0, sizeof(st));
|
|
102
|
+
|
|
103
|
+
while (len >= rate) {
|
|
104
|
+
for (i = 0; i < rate / 8; i++) {
|
|
105
|
+
st[i] ^= load64(data + (i * 8));
|
|
106
|
+
}
|
|
107
|
+
keccakf(st);
|
|
108
|
+
data += rate;
|
|
109
|
+
len -= rate;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
memset(temp, 0, rate);
|
|
113
|
+
if (len) {
|
|
114
|
+
memcpy(temp, data, len);
|
|
115
|
+
}
|
|
116
|
+
temp[len] = 0x01; /* Keccak padding */
|
|
117
|
+
temp[rate - 1] |= 0x80;
|
|
118
|
+
|
|
119
|
+
for (i = 0; i < rate / 8; i++) {
|
|
120
|
+
st[i] ^= load64(temp + (i * 8));
|
|
121
|
+
}
|
|
122
|
+
keccakf(st);
|
|
123
|
+
|
|
124
|
+
for (i = 0; i < 4; i++) {
|
|
125
|
+
store64(out + (i * 8), st[i]);
|
|
126
|
+
}
|
|
127
|
+
}
|
cchecksum/keccak.h
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from cchecksum._checksum import to_checksum_address
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def monkey_patch_eth_utils() -> None:
|
|
5
|
+
"""Monkey patch eth_utils to use cchecksum's implementation internally."""
|
|
6
|
+
import eth_utils
|
|
7
|
+
import eth_utils.address
|
|
8
|
+
|
|
9
|
+
eth_utils.to_checksum_address = to_checksum_address
|
|
10
|
+
eth_utils.address.to_checksum_address = to_checksum_address
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def monkey_patch_web3py() -> None:
|
|
14
|
+
"""Monkey patch web3.py to use cchecksum's implementation internally."""
|
|
15
|
+
import web3._utils as web3_utils
|
|
16
|
+
import web3.main as web3_main
|
|
17
|
+
import web3.middleware as web3_middleware
|
|
18
|
+
|
|
19
|
+
web3_main.to_checksum_address = to_checksum_address
|
|
20
|
+
web3_utils.ens.to_checksum_address = to_checksum_address
|
|
21
|
+
web3_utils.method_formatters.to_checksum_address = to_checksum_address
|
|
22
|
+
web3_utils.normalizers.to_checksum_address = to_checksum_address
|
|
23
|
+
web3_middleware.signing.to_checksum_address = to_checksum_address
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
import web3.utils.address as web3_address
|
|
27
|
+
|
|
28
|
+
web3_address.to_checksum_address = to_checksum_address
|
|
29
|
+
except ModuleNotFoundError:
|
|
30
|
+
# youre on an older web3py, no monkey patch for you
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
import ens.ens
|
|
35
|
+
|
|
36
|
+
ens.ens.to_checksum_address = to_checksum_address
|
|
37
|
+
except ModuleNotFoundError:
|
|
38
|
+
# youre on an older web3py, no monkey patch for you
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
import ens.async_ens
|
|
43
|
+
|
|
44
|
+
ens.async_ens.to_checksum_address = to_checksum_address
|
|
45
|
+
except ModuleNotFoundError:
|
|
46
|
+
# youre on an older web3py, no monkey patch for you
|
|
47
|
+
pass
|
cchecksum/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cchecksum
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: An ~18x faster drop-in replacement for eth_utils.to_checksum_address. Raises the exact same Exceptions. Implemented in C.
|
|
5
|
+
Home-page: https://github.com/BobTheBuidler/cchecksum
|
|
6
|
+
Author: BobTheBuidler
|
|
7
|
+
Author-email: bobthebuidlerdefi@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: >=3.9,<4
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: eth-hash
|
|
24
|
+
Requires-Dist: eth-typing
|
|
25
|
+
Requires-Dist: pysha3<2.0.0,>=1.0.0; python_version < "3.9"
|
|
26
|
+
Requires-Dist: safe-pysha3>=1.0.0; python_version >= "3.9"
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: author-email
|
|
29
|
+
Dynamic: classifier
|
|
30
|
+
Dynamic: description
|
|
31
|
+
Dynamic: description-content-type
|
|
32
|
+
Dynamic: home-page
|
|
33
|
+
Dynamic: license
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
Dynamic: requires-dist
|
|
36
|
+
Dynamic: requires-python
|
|
37
|
+
Dynamic: summary
|
|
38
|
+
|
|
39
|
+
## CChecksum
|
|
40
|
+
|
|
41
|
+
[](https://pypi.org/project/cchecksum/)
|
|
42
|
+
[](https://pypistats.org/packages/cchecksum)
|
|
43
|
+
|
|
44
|
+
CChecksum is an ~18x faster drop-in replacement for `eth_utils.to_checksum_address`, with the most cpu-intensive part implemented in C.
|
|
45
|
+
|
|
46
|
+
It keeps the exact same API as the existing implementation, exceptions and all.
|
|
47
|
+
|
|
48
|
+
Just `pip install cchecksum`, drop it in, and run your script with a substantial speed improvement.
|
|
49
|
+
|
|
50
|
+

|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
benchmarks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
benchmarks/data.py,sha256=NAL981tXOCM0OAsvmAo5oaclUbn_ChyfHhJAovCQSCw,2591
|
|
3
|
+
benchmarks/test_checksum_benchmarks.py,sha256=uLiog8i55v1gWLu036vU9CE7A9rOZC215qVmsYCM5RU,856
|
|
4
|
+
cchecksum/__init__.py,sha256=_-USjJJuqlD5ZlfwoIH7CZ3AqHqfc90u9wvZVO4lJ_s,509
|
|
5
|
+
cchecksum/_checksum.c,sha256=OuARta6Pc_t3cqhpqxSPnUE_qGIRGJve0lm3F20usF4,1217643
|
|
6
|
+
cchecksum/_checksum.cpython-312-i386-linux-musl.so,sha256=A6ZtGm33mpzbeQvnVXgdsHWudO7Gb-ueIjJFReTR3uY,1197476
|
|
7
|
+
cchecksum/_checksum.pyi,sha256=DyI9c_d4UNkwNO5XHCCHiTWgLliG4CwEIX0PaLX8fMs,2755
|
|
8
|
+
cchecksum/_checksum.pyx,sha256=cmoJY5R16FIstEytGCHqpDSA12z8FAMeEO-I7nD-niU,18667
|
|
9
|
+
cchecksum/keccak.c,sha256=Ay2A9b5X0S5lGx9b8yvYCpDgOJ6jponpFojK0_yWoUE,3581
|
|
10
|
+
cchecksum/keccak.h,sha256=MnX0M_EVIFCq2HttcqV7554pKlNVnk8Bf0ziQ9Bkt-c,160
|
|
11
|
+
cchecksum/monkey_patch.py,sha256=ZCHPmfgeD6nOY9Gw2wU8d5qsBJMX-gymS-FryZ63IfQ,1540
|
|
12
|
+
cchecksum/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
cchecksum-0.4.0.dist-info/METADATA,sha256=TV200gOsCiEIuZiiEi0T35rHsKkgRgyFstDQVtygdbQ,2031
|
|
14
|
+
cchecksum-0.4.0.dist-info/WHEEL,sha256=Vuwis_LWaa45QUuJ2qqSgABfO0elv3qQohyjTF3DnPc,110
|
|
15
|
+
cchecksum-0.4.0.dist-info/top_level.txt,sha256=p1_Dp2Nve349aJTTUwPd8mo5iBFLnaq2cCT8EbsfQc0,21
|
|
16
|
+
cchecksum-0.4.0.dist-info/RECORD,,
|
|
17
|
+
cchecksum-0.4.0.dist-info/licenses/LICENSE,sha256=qakxXN2B307yD6T3mvzxR7reyaih9WyLgpLoA3QoWdI,1070
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 BobTheBuidler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|