Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor WriteHolder from seed to nonce (261-restrict-write-instruction)
  • Loading branch information
vakond committed Oct 21, 2021
commit 04d706cbb24d66216a9f0edb7caada5857949871
5 changes: 3 additions & 2 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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')
Expand Down
14 changes: 7 additions & 7 deletions proxy/plugin/solana_rest_api_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1137,19 +1137,19 @@ 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
offset = 0
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),
Expand Down Expand Up @@ -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")
Expand Down