mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-24 17:08:46 +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 "address.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "bignum.h"
|
#include "bignum.h"
|
||||||
|
|
||||||
size_t address_prefix_bytes_len(uint32_t address_type)
|
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
|
#if USE_ETHEREUM
|
||||||
#include "sha3.h"
|
#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";
|
const char *hex = "0123456789abcdef";
|
||||||
for (int i = 0; i < 20; i++) {
|
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;
|
SHA3_CTX ctx;
|
||||||
uint8_t hash[32];
|
uint8_t hash[32];
|
||||||
keccak_256_Init(&ctx);
|
keccak_256_Init(&ctx);
|
||||||
if(rskip60)
|
if (rskip60) {
|
||||||
{
|
|
||||||
char prefix[16];
|
char prefix[16];
|
||||||
int prefix_size = bn_format_uint64(chain_id, NULL, "0x", 0, 0, false, prefix, sizeof(prefix));
|
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);
|
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);
|
void address_write_prefix_bytes(uint32_t address_type, uint8_t *out);
|
||||||
bool address_check_prefix(const uint8_t *addr, uint32_t address_type);
|
bool address_check_prefix(const uint8_t *addr, uint32_t address_type);
|
||||||
#if USE_ETHEREUM
|
#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
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3802,7 +3802,7 @@ START_TEST(test_ethereum_address)
|
|||||||
const char **vec = vectors;
|
const char **vec = vectors;
|
||||||
while (*vec) {
|
while (*vec) {
|
||||||
memcpy(addr, fromhex(*vec), 20);
|
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);
|
ck_assert_str_eq(address, *vec);
|
||||||
vec++;
|
vec++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user