From 13a71d115bb29d304ea05dc47e7e10bc58debc2f Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Tue, 5 Oct 2021 19:40:42 +0300 Subject: [PATCH 01/12] Use keccak_256 instead of shake_256 (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index 9eb95800c..9e4b73ff7 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -21,7 +21,7 @@ from ..http.server import HttpWebServerBasePlugin, httpProtocolTypes from .eth_proto import Trx as EthTrx from solana.rpc.api import Client as SolanaClient -from sha3 import keccak_256, shake_256 +from sha3 import keccak_256 import base58 import traceback import threading @@ -53,11 +53,11 @@ def __init__(self, client, signer, proxy_id): proxy_id_bytes = proxy_id.to_bytes((proxy_id.bit_length() + 7) // 8, 'big') signer_public_key_bytes = bytes(signer.public_key()) - storage_seed = shake_256(b"storage" + proxy_id_bytes + signer_public_key_bytes).hexdigest(16) + storage_seed = keccak_256(b"storage" + proxy_id_bytes + signer_public_key_bytes).hexdigest()[:32] storage_seed = bytes(storage_seed, 'utf8') self.storage = create_account_with_seed(client, funding=signer, base=signer, seed=storage_seed, storage_size=STORAGE_SIZE) - holder_seed = shake_256(b"holder" + proxy_id_bytes + signer_public_key_bytes).hexdigest(16) + holder_seed = keccak_256(b"holder" + proxy_id_bytes + signer_public_key_bytes).hexdigest()[:32] holder_seed = bytes(holder_seed, 'utf8') self.holder = create_account_with_seed(client, funding=signer, base=signer, seed=holder_seed, storage_size=STORAGE_SIZE) From 9e8a5453f0e9f9dac65a3a34c0e81069028c59ba Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Wed, 6 Oct 2021 20:13:32 +0300 Subject: [PATCH 02/12] Use WriteHolder (15=0x0F) instead of Write (0) (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api.py | 4 ++-- proxy/plugin/solana_rest_api_tools.py | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index 5c70ac83f..c79b356de 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -58,8 +58,8 @@ def __init__(self, client, signer, proxy_id): self.storage = create_account_with_seed(client, funding=signer, base=signer, seed=storage_seed, storage_size=STORAGE_SIZE) holder_seed = keccak_256(b"holder" + proxy_id_bytes + signer_public_key_bytes).hexdigest()[:32] - holder_seed = bytes(holder_seed, 'utf8') - self.holder = create_account_with_seed(client, funding=signer, base=signer, seed=holder_seed, storage_size=STORAGE_SIZE) + self.holder_seed = bytes(holder_seed, 'utf8') + self.holder = create_account_with_seed(client, funding=signer, base=signer, seed=self.holder_seed, storage_size=STORAGE_SIZE) collateral_pool_index = proxy_id % 4 self.collateral_pool_index_buf = collateral_pool_index.to_bytes(4, 'little') diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index df6a344b0..5f085b331 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -92,7 +92,6 @@ AccountMeta(pubkey=sysvarclock, is_signer=False, is_writable=False), ] - class TransactionAccounts: def __init__(self, caller_token, eth_accounts): self.caller_token = caller_token @@ -115,8 +114,9 @@ def create_account_layout(lamports, space, ether, nonce): nonce=nonce )) -def write_layout(offset, data): - return (bytes.fromhex("00000000")+ +def write_holder_layout(seed, offset, data): + return (bytes.fromhex("0F")+ + seed+ offset.to_bytes(4, byteorder="little")+ len(data).to_bytes(8, byteorder="little")+ data) @@ -978,7 +978,7 @@ def call_signed_noniterative(signer, client, ethTrx, perm_accs, trx_accs, msg, c def call_signed_with_holder_acc(signer, client, ethTrx, perm_accs, trx_accs, steps, create_acc_trx): - write_trx_to_holder_account(signer, client, perm_accs.holder, ethTrx) + write_trx_to_holder_account(signer, client, perm_accs.holder, perm_accs.holder_seed, ethTrx) if len(create_acc_trx.instructions): precall_txs = Transaction() @@ -1042,7 +1042,7 @@ def createEtherAccountTrx(client, ether, evm_loader_id, signer, code_acc=None): return (trx, sol, associated_token) -def write_trx_to_holder_account(signer, client, holder, ethTrx): +def write_trx_to_holder_account(signer, client, holder, holder_seed, ethTrx): msg = ethTrx.signature() + len(ethTrx.unsigned_msg()).to_bytes(8, byteorder="little") + ethTrx.unsigned_msg() # Write transaction to transaction holder account @@ -1054,7 +1054,7 @@ def write_trx_to_holder_account(signer, client, holder, ethTrx): trx = Transaction() # logger.debug("sender_sol %s %s %s", sender_sol, holder, acc.public_key()) trx.add(TransactionInstruction(program_id=evm_loader_id, - data=write_layout(offset, part), + data=write_holder_layout(holder_seed, offset, part), keys=[ AccountMeta(pubkey=holder, is_signer=False, is_writable=True), AccountMeta(pubkey=signer.public_key(), is_signer=True, is_writable=False), @@ -1092,7 +1092,7 @@ def deploy_contract(signer, client, ethTrx, perm_accs, steps): logger.debug("Legacy contract address solana: %s %s", contract_sol, contract_nonce) logger.debug("Legacy code address solana: %s %s", code_sol, code_nonce) - write_trx_to_holder_account(signer, client, perm_accs.holder, ethTrx) + write_trx_to_holder_account(signer, client, perm_accs.holder, perm_accs.holder_seed, ethTrx) # Create contract account & execute deploy transaction logger.debug(" # Create contract account & execute deploy transaction") From 4abbda541379827d71fcfcbc0903e10ff94a1f81 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Mon, 11 Oct 2021 20:14:08 +0300 Subject: [PATCH 03/12] WriteHolder index: 15 => 16 (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api_tools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index 810ba4c85..e9d080255 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -115,10 +115,10 @@ def create_account_layout(lamports, space, ether, nonce): )) def write_holder_layout(seed, offset, data): - return (bytes.fromhex("0F")+ + return (bytes.fromhex('10')+ seed+ - offset.to_bytes(4, byteorder="little")+ - len(data).to_bytes(8, byteorder="little")+ + offset.to_bytes(4, byteorder='little')+ + len(data).to_bytes(8, byteorder='little')+ data) def accountWithSeed(base, seed, program): From f60eee954cd164eff28f7afd12ea5b8bea21fb8e Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Mon, 18 Oct 2021 17:57:53 +0300 Subject: [PATCH 04/12] WriteHolder index: 16 => 17 (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index e9d080255..d2f52942c 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -115,7 +115,7 @@ def create_account_layout(lamports, space, ether, nonce): )) def write_holder_layout(seed, offset, data): - return (bytes.fromhex('10')+ + return (bytes.fromhex('11')+ seed+ offset.to_bytes(4, byteorder='little')+ len(data).to_bytes(8, byteorder='little')+ From 8c96419e2da4d9c4a9f14d55aa376d83f0366c11 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Tue, 19 Oct 2021 19:26:32 +0300 Subject: [PATCH 05/12] WriteHolder index: 17 => 18 (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index 756f6ff5d..060ab4d66 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -117,7 +117,7 @@ def create_account_layout(lamports, space, ether, nonce): )) def write_holder_layout(seed, offset, data): - return (bytes.fromhex('11')+ + return (bytes.fromhex('12')+ seed+ offset.to_bytes(4, byteorder='little')+ len(data).to_bytes(8, byteorder='little')+ @@ -855,7 +855,7 @@ def create_account_list_by_emulate(signer, client, ethTrx): AccountMeta(pubkey=signer.public_key(), is_signer=True, is_writable=False) ], program_id=evm_loader_id, - data=bytearray.fromhex("11")+bytes(seed) # 17- ResizeStorageAccount + data=bytearray.fromhex("12")+bytes(seed) # 17- ResizeStorageAccount )) # replace code_account acc_desc["contract"] = code_account_new From a5bbb43376a215a25194060ad6412eb741f29bc7 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Tue, 19 Oct 2021 20:14:41 +0300 Subject: [PATCH 06/12] WriteHolder instruction creates bigger trx due to seed (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index 060ab4d66..bc50d5194 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -1145,9 +1145,9 @@ def write_trx_to_holder_account(signer, client, holder, holder_seed, ethTrx): receipts = [] rest = msg while len(rest): - (part, rest) = (rest[:1000], rest[1000:]) + (part, rest) = (rest[:800], rest[800:]) trx = Transaction() - # logger.debug("sender_sol %s %s %s", sender_sol, holder, acc.public_key()) + logger.debug("sender_sol %s %s %s", sender_sol, holder, acc.public_key()) trx.add(TransactionInstruction(program_id=evm_loader_id, data=write_holder_layout(holder_seed, offset, part), keys=[ From 27eac905193ed9045765a7bd6aecf5aa6aa234d5 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Tue, 19 Oct 2021 20:15:48 +0300 Subject: [PATCH 07/12] WriteHolder instruction creates bigger trx due to seed (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index bc50d5194..d014a8d5d 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -1145,7 +1145,7 @@ def write_trx_to_holder_account(signer, client, holder, holder_seed, ethTrx): receipts = [] rest = msg while len(rest): - (part, rest) = (rest[:800], rest[800:]) + (part, rest) = (rest[:900], rest[900:]) trx = Transaction() logger.debug("sender_sol %s %s %s", sender_sol, holder, acc.public_key()) trx.add(TransactionInstruction(program_id=evm_loader_id, From 1472ae3b8ddb2bf74a1f3d2a3ef0cb4ad72e2699 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Tue, 19 Oct 2021 20:29:46 +0300 Subject: [PATCH 08/12] Comment unneeded logging (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index d014a8d5d..c6f3b7543 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -1147,7 +1147,7 @@ def write_trx_to_holder_account(signer, client, holder, holder_seed, ethTrx): while len(rest): (part, rest) = (rest[:900], rest[900:]) trx = Transaction() - logger.debug("sender_sol %s %s %s", sender_sol, holder, acc.public_key()) + # logger.debug("sender_sol %s %s %s", sender_sol, holder, acc.public_key()) trx.add(TransactionInstruction(program_id=evm_loader_id, data=write_holder_layout(holder_seed, offset, part), keys=[ From f8edc4b462a2189db226ef388ff2d6d747cb33f3 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Tue, 19 Oct 2021 22:05:08 +0300 Subject: [PATCH 09/12] bugfix (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index c6f3b7543..238de5592 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -855,7 +855,7 @@ def create_account_list_by_emulate(signer, client, ethTrx): AccountMeta(pubkey=signer.public_key(), is_signer=True, is_writable=False) ], program_id=evm_loader_id, - data=bytearray.fromhex("12")+bytes(seed) # 17- ResizeStorageAccount + data=bytearray.fromhex("11")+bytes(seed) # 17- ResizeStorageAccount )) # replace code_account acc_desc["contract"] = code_account_new From 04d706cbb24d66216a9f0edb7caada5857949871 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Thu, 21 Oct 2021 21:02:14 +0300 Subject: [PATCH 10/12] Refactor WriteHolder from seed to nonce (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api.py | 5 +++-- proxy/plugin/solana_rest_api_tools.py | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index 53f4ddcb4..4ac6b323d 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -49,6 +49,7 @@ class PermanentAccounts: def __init__(self, client, signer, proxy_id): self.operator = signer.public_key() self.operator_token = getTokenAddr(self.operator) + self.proxy_id = proxy_id proxy_id_bytes = proxy_id.to_bytes((proxy_id.bit_length() + 7) // 8, 'big') signer_public_key_bytes = bytes(signer.public_key()) @@ -58,8 +59,8 @@ def __init__(self, client, signer, proxy_id): self.storage = create_account_with_seed(client, funding=signer, base=signer, seed=storage_seed, storage_size=STORAGE_SIZE) holder_seed = keccak_256(b"holder" + proxy_id_bytes + signer_public_key_bytes).hexdigest()[:32] - self.holder_seed = bytes(holder_seed, 'utf8') - self.holder = create_account_with_seed(client, funding=signer, base=signer, seed=self.holder_seed, storage_size=STORAGE_SIZE) + holder_seed = bytes(holder_seed, 'utf8') + self.holder = create_account_with_seed(client, funding=signer, base=signer, seed=holder_seed, storage_size=STORAGE_SIZE) collateral_pool_index = proxy_id % 4 self.collateral_pool_index_buf = collateral_pool_index.to_bytes(4, 'little') diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index 02f556881..f33e6afa1 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -116,9 +116,9 @@ def create_account_layout(lamports, space, ether, nonce): nonce=nonce )) -def write_holder_layout(seed, offset, data): +def write_holder_layout(nonce, offset, data): return (bytes.fromhex('12')+ - seed+ + nonce.to_bytes(8, byteorder='little')+ offset.to_bytes(4, byteorder='little')+ len(data).to_bytes(8, byteorder='little')+ data) @@ -1054,7 +1054,7 @@ def call_signed_noniterative(signer, client, ethTrx, perm_accs, trx_accs, msg, c def call_signed_with_holder_acc(signer, client, ethTrx, perm_accs, trx_accs, steps, create_acc_trx): - write_trx_to_holder_account(signer, client, perm_accs.holder, perm_accs.holder_seed, ethTrx) + write_trx_to_holder_account(signer, client, perm_accs.holder, perm_accs.proxy_id, ethTrx) if len(create_acc_trx.instructions): precall_txs = Transaction() @@ -1137,7 +1137,7 @@ def createERC20TokenAccountTrx(signer, token_info): -def write_trx_to_holder_account(signer, client, holder, holder_seed, ethTrx): +def write_trx_to_holder_account(signer, client, holder, proxy_id, ethTrx): msg = ethTrx.signature() + len(ethTrx.unsigned_msg()).to_bytes(8, byteorder="little") + ethTrx.unsigned_msg() # Write transaction to transaction holder account @@ -1145,11 +1145,11 @@ def write_trx_to_holder_account(signer, client, holder, holder_seed, ethTrx): receipts = [] rest = msg while len(rest): - (part, rest) = (rest[:900], rest[900:]) + (part, rest) = (rest[:1000], rest[1000:]) trx = Transaction() # logger.debug("sender_sol %s %s %s", sender_sol, holder, acc.public_key()) trx.add(TransactionInstruction(program_id=evm_loader_id, - data=write_holder_layout(holder_seed, offset, part), + data=write_holder_layout(proxy_id, offset, part), keys=[ AccountMeta(pubkey=holder, is_signer=False, is_writable=True), AccountMeta(pubkey=signer.public_key(), is_signer=True, is_writable=False), @@ -1187,7 +1187,7 @@ def deploy_contract(signer, client, ethTrx, perm_accs, steps): logger.debug("Legacy contract address solana: %s %s", contract_sol, contract_nonce) logger.debug("Legacy code address solana: %s %s", code_sol, code_nonce) - write_trx_to_holder_account(signer, client, perm_accs.holder, perm_accs.holder_seed, ethTrx) + write_trx_to_holder_account(signer, client, perm_accs.holder, perm_accs.proxy_id, ethTrx) # Create contract account & execute deploy transaction logger.debug(" # Create contract account & execute deploy transaction") From 2eabd94bddf7f31c12f844999b6859fd3e3ad1a2 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Wed, 27 Oct 2021 16:13:51 +0300 Subject: [PATCH 11/12] Exclude signer pubkey from seed generation (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index 4ac6b323d..a3e2489b6 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -52,13 +52,12 @@ def __init__(self, client, signer, proxy_id): self.proxy_id = proxy_id proxy_id_bytes = proxy_id.to_bytes((proxy_id.bit_length() + 7) // 8, 'big') - signer_public_key_bytes = bytes(signer.public_key()) - storage_seed = keccak_256(b"storage" + proxy_id_bytes + signer_public_key_bytes).hexdigest()[:32] + storage_seed = keccak_256(b"storage" + proxy_id_bytes).hexdigest()[:32] storage_seed = bytes(storage_seed, 'utf8') self.storage = create_account_with_seed(client, funding=signer, base=signer, seed=storage_seed, storage_size=STORAGE_SIZE) - holder_seed = keccak_256(b"holder" + proxy_id_bytes + signer_public_key_bytes).hexdigest()[:32] + holder_seed = keccak_256(b"holder" + proxy_id_bytes).hexdigest()[:32] holder_seed = bytes(holder_seed, 'utf8') self.holder = create_account_with_seed(client, funding=signer, base=signer, seed=holder_seed, storage_size=STORAGE_SIZE) From 8e10e012511ce95a5d68ef1e73c15cb8d95795e5 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Thu, 28 Oct 2021 08:53:42 +0300 Subject: [PATCH 12/12] Remove dead code (261-restrict-write-instruction) --- proxy/plugin/solana_rest_api_tools.py | 76 --------------------------- 1 file changed, 76 deletions(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index 84177bfcd..8e1011e80 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -1167,82 +1167,6 @@ def write_trx_to_holder_account(signer, client, holder, proxy_id, ethTrx): confirm_transaction(client, rcpt) logger.debug("confirmed: %s", rcpt) - -def deploy_contract(signer, client, ethTrx, perm_accs, steps): - sender_ether = bytes.fromhex(ethTrx.sender()) - (sender_sol, _) = ether2program(sender_ether.hex(), evm_loader_id, signer.public_key()) - logger.debug("Sender account solana: %s %s", sender_ether.hex(), sender_sol) - - caller_token = get_associated_token_address(PublicKey(sender_sol), ETH_TOKEN_MINT_ID) - - #info = _getAccountData(client, sender_sol, ACCOUNT_INFO_LAYOUT.sizeof()) - #trx_count = int.from_bytes(AccountInfo.frombytes(info).trx_count, 'little') - #logger.debug("Sender solana trx_count: %s", trx_count) - - # Create legacy contract address from (sender_eth, nonce) - #rlp = pack(sender_ether, ethTrx.nonce or None) - contract_eth = keccak_256(rlp.encode((sender_ether, ethTrx.nonce))).digest()[-20:] - (contract_sol, contract_nonce) = ether2program(contract_eth.hex(), evm_loader_id, signer.public_key()) - - # We need append ACCOUNT_SEED_VERSION to created CODE account (to avoid using previously created accounts to store the code) - # when calculate contract_sol variable ACCOUNT_SEED_VERSION already added in `neon-cli create-program-address`. - (code_sol, code_nonce, code_seed) = ether2seed(ACCOUNT_SEED_VERSION+contract_eth, evm_loader_id, signer.public_key()) - - logger.debug("Legacy contract address ether: %s", contract_eth.hex()) - logger.debug("Legacy contract address solana: %s %s", contract_sol, contract_nonce) - logger.debug("Legacy code address solana: %s %s", code_sol, code_nonce) - - write_trx_to_holder_account(signer, client, perm_accs.holder, perm_accs.proxy_id, ethTrx) - - # Create contract account & execute deploy transaction - logger.debug(" # Create contract account & execute deploy transaction") - trx = Transaction() - sender_sol_info = client.get_account_info(sender_sol, commitment=Confirmed) - if sender_sol_info['result']['value'] is None: - trx.add(createEtherAccountTrx(client, sender_ether, evm_loader_id, signer)[0]) - if NEW_USER_AIRDROP_AMOUNT > 0: - trx.add(transfer2(Transfer2Params( - source=getTokenAddr(signer.public_key()), - owner=signer.public_key(), - dest=caller_token, - amount=NEW_USER_AIRDROP_AMOUNT*1_000_000_000, - decimals=9, - mint=ETH_TOKEN_MINT_ID, - program_id=TOKEN_PROGRAM_ID, - ))) - logger.debug("Token transfer to %s as ethereum 0x%s amount %s", caller_token, ethTrx.sender(), str(NEW_USER_AIRDROP_AMOUNT)) - - if client.get_balance(code_sol, commitment=Confirmed)['result']['value'] == 0: - msg_size = len(ethTrx.signature() + len(ethTrx.unsigned_msg()).to_bytes(8, byteorder="little") + ethTrx.unsigned_msg()) - valids_size = (msg_size // 8) + 1 - code_account_size = CODE_INFO_LAYOUT.sizeof() + msg_size + valids_size + 2048 - code_account_balance = client.get_minimum_balance_for_rent_exemption(code_account_size)["result"] - trx.add(createAccountWithSeedTrx(signer.public_key(), signer.public_key(), code_seed, code_account_balance, code_account_size, PublicKey(evm_loader_id))) - if client.get_balance(contract_sol, commitment=Confirmed)['result']['value'] == 0: - trx.add(createEtherAccountTrx(client, contract_eth, evm_loader_id, signer, code_sol)[0]) - if len(trx.instructions): - result = send_measured_transaction(client, trx, signer) - - eth_accounts = [ - AccountMeta(pubkey=contract_sol, is_signer=False, is_writable=True), - AccountMeta(pubkey=get_associated_token_address(PublicKey(contract_sol), ETH_TOKEN_MINT_ID), is_signer=False, is_writable=True), - AccountMeta(pubkey=code_sol, is_signer=False, is_writable=True), - AccountMeta(pubkey=sender_sol, is_signer=False, is_writable=True), - AccountMeta(pubkey=caller_token, is_signer=False, is_writable=True), - ] - - trx_accs = TransactionAccounts(caller_token, eth_accounts) - - precall_txs = Transaction() - precall_txs.add(make_call_from_account_instruction(perm_accs, trx_accs)) - - # ExecuteTrxFromAccountDataIterative - logger.debug("ExecuteTrxFromAccountDataIterative:") - send_measured_transaction(client, precall_txs, signer) - - return (call_continue(signer, client, perm_accs, trx_accs, steps), '0x'+contract_eth.hex()) - - def _getAccountData(client, account, expected_length, owner=None): info = client.get_account_info(account, commitment=Confirmed)['result']['value'] if info is None: