Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
13a71d1
Use keccak_256 instead of shake_256 (261-restrict-write-instruction)
vakond Oct 5, 2021
9bb1924
Merge branch 'develop' into 261-restrict-write-instruction
vakond Oct 6, 2021
9e8a545
Use WriteHolder (15=0x0F) instead of Write (0) (261-restrict-write-in…
vakond Oct 6, 2021
28f1e5d
Merge branch 'develop' into 261-restrict-write-instruction
vakond Oct 7, 2021
d861d55
Merge develop (261-restrict-write-instruction)
vakond Oct 11, 2021
4abbda5
WriteHolder index: 15 => 16 (261-restrict-write-instruction)
vakond Oct 11, 2021
9913c0d
Merge branch 'develop' into 261-restrict-write-instruction
vakond Oct 15, 2021
58f5851
Merge branch 'develop' into 261-restrict-write-instruction
vakond Oct 16, 2021
68ac29a
Merge branch 'develop' into 261-restrict-write-instruction
vakond Oct 18, 2021
f60eee9
WriteHolder index: 16 => 17 (261-restrict-write-instruction)
vakond Oct 18, 2021
4888344
Merge branch 'develop' into 261-restrict-write-instruction
vakond Oct 19, 2021
8c96419
WriteHolder index: 17 => 18 (261-restrict-write-instruction)
vakond Oct 19, 2021
a5bbb43
WriteHolder instruction creates bigger trx due to seed (261-restrict-…
vakond Oct 19, 2021
27eac90
WriteHolder instruction creates bigger trx due to seed (261-restrict-…
vakond Oct 19, 2021
1472ae3
Comment unneeded logging (261-restrict-write-instruction)
vakond Oct 19, 2021
f8edc4b
bugfix (261-restrict-write-instruction)
vakond Oct 19, 2021
c9a0bbb
Merge branch 'develop' into 261-restrict-write-instruction
vakond Oct 21, 2021
04d706c
Refactor WriteHolder from seed to nonce (261-restrict-write-instruction)
vakond Oct 21, 2021
a02a789
Merge branch 'develop' into 261-restrict-write-instruction
vakond Oct 22, 2021
54ec920
Merge branch 'develop' into 261-restrict-write-instruction
vakond Oct 27, 2021
2eabd94
Exclude signer pubkey from seed generation (261-restrict-write-instru…
vakond Oct 27, 2021
8e10e01
Remove dead code (261-restrict-write-instruction)
vakond Oct 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,15 +49,15 @@ 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())

storage_seed = shake_256(b"storage" + proxy_id_bytes + signer_public_key_bytes).hexdigest(16)
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 = shake_256(b"holder" + proxy_id_bytes + signer_public_key_bytes).hexdigest(16)
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)

Expand Down
17 changes: 8 additions & 9 deletions proxy/plugin/solana_rest_api_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
AccountMeta(pubkey=sysvarclock, is_signer=False, is_writable=False),
]


class TransactionAccounts:
def __init__(self, caller_token, eth_accounts):
self.caller_token = caller_token
Expand All @@ -118,10 +117,11 @@ def create_account_layout(lamports, space, ether, nonce):
nonce=nonce
))

def write_layout(offset, data):
return (bytes.fromhex("00000000")+
offset.to_bytes(4, byteorder="little")+
len(data).to_bytes(8, byteorder="little")+
def write_holder_layout(nonce, offset, data):
return (bytes.fromhex('12')+
nonce.to_bytes(8, byteorder='little')+
offset.to_bytes(4, byteorder='little')+
len(data).to_bytes(8, byteorder='little')+
data)

def accountWithSeed(base, seed, program):
Expand Down Expand Up @@ -1059,7 +1059,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.proxy_id, ethTrx)

if len(create_acc_trx.instructions):
precall_txs = Transaction()
Expand Down Expand Up @@ -1142,7 +1142,7 @@ def createERC20TokenAccountTrx(signer, token_info):



def write_trx_to_holder_account(signer, client, holder, 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
Expand All @@ -1154,7 +1154,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(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),
Expand All @@ -1167,7 +1167,6 @@ def write_trx_to_holder_account(signer, client, holder, ethTrx):
confirm_transaction(client, rcpt)
logger.debug("confirmed: %s", rcpt)


def _getAccountData(client, account, expected_length, owner=None):
info = client.get_account_info(account, commitment=Confirmed)['result']['value']
if info is None:
Expand Down