From 599f775af2a0b5c8baf831d509c4196270a93f93 Mon Sep 17 00:00:00 2001 From: harkamal Date: Tue, 11 Jun 2024 18:19:17 +0530 Subject: [PATCH] incorpodate feedback --- packages/evm/src/opcodes/functions.ts | 3 ++- packages/util/src/bytes.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/evm/src/opcodes/functions.ts b/packages/evm/src/opcodes/functions.ts index 8b722db327..d6bdfc423d 100644 --- a/packages/evm/src/opcodes/functions.ts +++ b/packages/evm/src/opcodes/functions.ts @@ -1156,7 +1156,8 @@ export const handlers: Map = new Map([ return } - const expectedAddress = new Address(bigIntToAddressBytes(authority)) + // we don't want strick check here on authority being in address range just last 20 bytes + const expectedAddress = new Address(bigIntToAddressBytes(authority, false)) const account = (await runState.stateManager.getAccount(expectedAddress)) ?? new Account() if (account.isContract()) { diff --git a/packages/util/src/bytes.ts b/packages/util/src/bytes.ts index ece34f8c1e..6285d888b3 100644 --- a/packages/util/src/bytes.ts +++ b/packages/util/src/bytes.ts @@ -430,8 +430,13 @@ export const bigIntToUnpaddedBytes = (value: bigint): Uint8Array => { return unpadBytes(bigIntToBytes(value)) } -export const bigIntToAddressBytes = (value: bigint): Uint8Array => { - return setLengthLeft(bigIntToBytes(value), 20).slice(-20) +export const bigIntToAddressBytes = (value: bigint, strict: boolean = true): Uint8Array => { + const addressBytes = setLengthLeft(bigIntToBytes(value), 20) + if (strict && addressBytes.length > 20) { + throw Error(`Invalid address bytes length=${addressBytes.length} strict=${strict}`) + } + + return addressBytes.slice(-20) } /**