mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
address: fix ethereum address computation, chain_id is uint32
This commit is contained in:
parent
4153e662b6
commit
3e8974ff88
@ -22,8 +22,6 @@
|
||||
*/
|
||||
|
||||
#include "address.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "bignum.h"
|
||||
|
||||
size_t address_prefix_bytes_len(uint32_t address_type)
|
||||
@ -59,7 +57,7 @@ bool address_check_prefix(const uint8_t *addr, uint32_t address_type)
|
||||
#if USE_ETHEREUM
|
||||
#include "sha3.h"
|
||||
|
||||
void ethereum_address_checksum(const uint8_t *addr, char *address, bool rskip60, uint8_t chain_id)
|
||||
void ethereum_address_checksum(const uint8_t *addr, char *address, bool rskip60, uint32_t chain_id)
|
||||
{
|
||||
const char *hex = "0123456789abcdef";
|
||||
for (int i = 0; i < 20; i++) {
|
||||
@ -71,8 +69,7 @@ void ethereum_address_checksum(const uint8_t *addr, char *address, bool rskip60,
|
||||
SHA3_CTX ctx;
|
||||
uint8_t hash[32];
|
||||
keccak_256_Init(&ctx);
|
||||
if(rskip60)
|
||||
{
|
||||
if (rskip60) {
|
||||
char prefix[16];
|
||||
int prefix_size = bn_format_uint64(chain_id, NULL, "0x", 0, 0, false, prefix, sizeof(prefix));
|
||||
keccak_Update(&ctx, (const uint8_t *)prefix, prefix_size);
|
||||
|
@ -33,7 +33,7 @@ size_t address_prefix_bytes_len(uint32_t address_type);
|
||||
void address_write_prefix_bytes(uint32_t address_type, uint8_t *out);
|
||||
bool address_check_prefix(const uint8_t *addr, uint32_t address_type);
|
||||
#if USE_ETHEREUM
|
||||
void ethereum_address_checksum(const uint8_t *addr, char *address, bool rskip60, uint8_t chain_id);
|
||||
void ethereum_address_checksum(const uint8_t *addr, char *address, bool rskip60, uint32_t chain_id);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -3802,7 +3802,7 @@ START_TEST(test_ethereum_address)
|
||||
const char **vec = vectors;
|
||||
while (*vec) {
|
||||
memcpy(addr, fromhex(*vec), 20);
|
||||
ethereum_address_checksum(addr, address, false, 1);
|
||||
ethereum_address_checksum(addr, address, false, 0);
|
||||
ck_assert_str_eq(address, *vec);
|
||||
vec++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user