Skip to content

Commit 7225b83

Browse files
committed
Merge branch 'develop' into main
2 parents 983c3c3 + 0410c1c commit 7225b83

File tree

11 files changed

+50
-190
lines changed

11 files changed

+50
-190
lines changed

.github/workflows/contracts.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v2
19-
- name: Set up Python 3.9
19+
- name: Set up Python 3.8
2020
uses: actions/setup-python@v2
2121
with:
22-
python-version: 3.9
22+
python-version: 3.8
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip

contracts/ArgentAccount.cairo

Lines changed: 13 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
# CONSTANTS
2626
####################
2727
28-
const VERSION = '0.2.0' # '0.2.0' = 30 2E 32 2E 30 = 0x302E322E30 = 206933470768
28+
const VERSION = '0.2.1'
2929
3030
const CHANGE_SIGNER_SELECTOR = 1540130945889430637313403138889853410180247761946478946165786566748520529557
3131
const CHANGE_GUARDIAN_SELECTOR = 1374386526556551464817815908276843861478960435557596145330240747921847320237
@@ -40,13 +40,11 @@ const ESCAPE_SECURITY_PERIOD = 7*24*60*60 # set to e.g. 7 days in prod
4040
const ESCAPE_TYPE_GUARDIAN = 0
4141
const ESCAPE_TYPE_SIGNER = 1
4242
43-
const ERC156_ACCOUNT_INTERFACE = 0xf10dbd44
43+
const ERC165_ACCOUNT_INTERFACE = 0xf10dbd44
4444
4545
const TRUE = 1
4646
const FALSE = 0
4747
48-
const PREFIX_TRANSACTION = 'StarkNet Transaction'
49-
5048
####################
5149
# STRUCTS
5250
####################
@@ -169,6 +167,7 @@ func initialize{
169167
end
170168
171169
@external
170+
@raw_output
172171
func __execute__{
173172
syscall_ptr: felt*,
174173
pedersen_ptr: HashBuiltin*,
@@ -181,8 +180,8 @@ func __execute__{
181180
calldata: felt*,
182181
nonce: felt
183182
) -> (
184-
response_len: felt,
185-
response: felt*
183+
retdata_size: felt,
184+
retdata: felt*
186185
):
187186
alloc_locals
188187
@@ -199,21 +198,18 @@ func __execute__{
199198
# get the tx info
200199
let (tx_info) = get_tx_info()
201200
202-
# compute message hash
203-
let (hash) = hash_multicall(tx_info.account_contract_address, calls_len, calls, nonce, tx_info.max_fee, tx_info.version)
204-
205201
if calls_len == 1:
206202
if calls[0].to == tx_info.account_contract_address:
207203
tempvar signer_condition = (calls[0].selector - ESCAPE_GUARDIAN_SELECTOR) * (calls[0].selector - TRIGGER_ESCAPE_GUARDIAN_SELECTOR)
208204
tempvar guardian_condition = (calls[0].selector - ESCAPE_SIGNER_SELECTOR) * (calls[0].selector - TRIGGER_ESCAPE_SIGNER_SELECTOR)
209205
if signer_condition == 0:
210206
# validate signer signature
211-
validate_signer_signature(hash, tx_info.signature, tx_info.signature_len)
207+
validate_signer_signature(tx_info.transaction_hash, tx_info.signature, tx_info.signature_len)
212208
jmp do_execute
213209
end
214210
if guardian_condition == 0:
215211
# validate guardian signature
216-
validate_guardian_signature(hash, tx_info.signature, tx_info.signature_len)
212+
validate_guardian_signature(tx_info.transaction_hash, tx_info.signature, tx_info.signature_len)
217213
jmp do_execute
218214
end
219215
end
@@ -222,8 +218,8 @@ func __execute__{
222218
assert_no_self_call(tx_info.account_contract_address, calls_len, calls)
223219
end
224220
# validate signer and guardian signatures
225-
validate_signer_signature(hash, tx_info.signature, tx_info.signature_len)
226-
validate_guardian_signature(hash, tx_info.signature + 2, tx_info.signature_len - 2)
221+
validate_signer_signature(tx_info.transaction_hash, tx_info.signature, tx_info.signature_len)
222+
validate_guardian_signature(tx_info.transaction_hash, tx_info.signature + 2, tx_info.signature_len - 2)
227223
228224
# execute calls
229225
do_execute:
@@ -234,8 +230,8 @@ func __execute__{
234230
let (response : felt*) = alloc()
235231
let (response_len) = execute_list(calls_len, calls, response)
236232
# emit event
237-
transaction_executed.emit(hash=hash, response_len=response_len, response=response)
238-
return (response_len=response_len, response=response)
233+
transaction_executed.emit(hash=tx_info.transaction_hash, response_len=response_len, response=response)
234+
return (retdata_size=response_len, retdata=response)
239235
end
240236
241237
@external
@@ -250,7 +246,7 @@ func upgrade{
250246
assert_only_self()
251247
# make sure the target is an account
252248
with_attr error_message("implementation invalid"):
253-
let (success) = IAccount.supportsInterface(contract_address=implementation, interfaceId=ERC156_ACCOUNT_INTERFACE)
249+
let (success) = IAccount.supportsInterface(contract_address=implementation, interfaceId=ERC165_ACCOUNT_INTERFACE)
254250
assert success = TRUE
255251
end
256252
# change implementation
@@ -506,7 +502,7 @@ func supportsInterface{
506502
return (TRUE)
507503
end
508504
# IAccount
509-
if interfaceId == ERC156_ACCOUNT_INTERFACE:
505+
if interfaceId == ERC165_ACCOUNT_INTERFACE:
510506
return (TRUE)
511507
end
512508
return (FALSE)
@@ -725,120 +721,6 @@ func execute_list{
725721
return (response_len + res.retdata_size)
726722
end
727723
728-
# @notice Computes the hash of a multicall to the `execute` method.
729-
# @param calls_len The legnth of the array of `Call`
730-
# @param calls A pointer to the array of `Call`
731-
# @param nonce The nonce for the multicall transaction
732-
# @param max_fee The max fee the user is willing to pay for the multicall
733-
# @param version The version of transaction in the Cairo OS. Always set to 0.
734-
# @return res The hash of the multicall
735-
func hash_multicall{
736-
syscall_ptr: felt*,
737-
pedersen_ptr: HashBuiltin*
738-
} (
739-
account: felt,
740-
calls_len: felt,
741-
calls: Call*,
742-
nonce: felt,
743-
max_fee: felt,
744-
version: felt
745-
) -> (res: felt):
746-
alloc_locals
747-
let (calls_hash) = hash_call_array(calls_len, calls)
748-
let hash_ptr = pedersen_ptr
749-
with hash_ptr:
750-
let (hash_state_ptr) = hash_init()
751-
let (hash_state_ptr) = hash_update_single(hash_state_ptr, PREFIX_TRANSACTION)
752-
let (hash_state_ptr) = hash_update_single(hash_state_ptr, account)
753-
let (hash_state_ptr) = hash_update_single(hash_state_ptr, calls_hash)
754-
let (hash_state_ptr) = hash_update_single(hash_state_ptr, nonce)
755-
let (hash_state_ptr) = hash_update_single(hash_state_ptr, max_fee)
756-
let (hash_state_ptr) = hash_update_single(hash_state_ptr, version)
757-
let (res) = hash_finalize(hash_state_ptr)
758-
let pedersen_ptr = hash_ptr
759-
return (res=res)
760-
end
761-
end
762-
763-
# @notice Computes the hash of an array of `Call`
764-
# @param calls_len The legnth of the array of `Call`
765-
# @param calls A pointer to the array of `Call`
766-
# @return res The hash of the array of `Call`
767-
func hash_call_array{
768-
pedersen_ptr: HashBuiltin*
769-
}(
770-
calls_len: felt,
771-
calls: Call*
772-
) -> (
773-
res: felt
774-
):
775-
alloc_locals
776-
777-
let (hash_array : felt*) = alloc()
778-
hash_call_loop(calls_len, calls, hash_array)
779-
780-
let hash_ptr = pedersen_ptr
781-
with hash_ptr:
782-
let (hash_state_ptr) = hash_init()
783-
let (hash_state_ptr) = hash_update(hash_state_ptr, hash_array, calls_len)
784-
let (res) = hash_finalize(hash_state_ptr)
785-
let pedersen_ptr = hash_ptr
786-
return (res=res)
787-
end
788-
end
789-
790-
# @notice Turns an array of `Call` into an array of `hash(Call)`
791-
# @param calls_len The legnth of the array of `Call`
792-
# @param calls A pointer to the array of `Call`
793-
# @param hash_array A pointer to the array of `hash(Call)`
794-
func hash_call_loop{
795-
pedersen_ptr: HashBuiltin*
796-
} (
797-
calls_len: felt,
798-
calls: Call*,
799-
hash_array: felt*
800-
):
801-
if calls_len == 0:
802-
return ()
803-
end
804-
let this_call = [calls]
805-
let (calldata_hash) = hash_calldata(this_call.calldata_len, this_call.calldata)
806-
let hash_ptr = pedersen_ptr
807-
with hash_ptr:
808-
let (hash_state_ptr) = hash_init()
809-
let (hash_state_ptr) = hash_update_single(hash_state_ptr, this_call.to)
810-
let (hash_state_ptr) = hash_update_single(hash_state_ptr, this_call.selector)
811-
let (hash_state_ptr) = hash_update_single(hash_state_ptr, calldata_hash)
812-
let (res) = hash_finalize(hash_state_ptr)
813-
let pedersen_ptr = hash_ptr
814-
assert [hash_array] = res
815-
end
816-
hash_call_loop(calls_len - 1, calls + Call.SIZE, hash_array + 1)
817-
return()
818-
end
819-
820-
# @notice Computes the hash of calldata as an array of felt
821-
# @param calldata_len The length of the calldata array
822-
# @param calldata A pointer to the calldata array
823-
# @return the hash of the calldata
824-
func hash_calldata{
825-
pedersen_ptr: HashBuiltin*
826-
} (
827-
calldata_len: felt,
828-
calldata: felt*,
829-
) -> (
830-
res: felt
831-
):
832-
let hash_ptr = pedersen_ptr
833-
with hash_ptr:
834-
let (hash_state_ptr) = hash_init()
835-
let (hash_state_ptr) = hash_update(hash_state_ptr, calldata, calldata_len)
836-
let (res) = hash_finalize(hash_state_ptr)
837-
let pedersen_ptr = hash_ptr
838-
return (res=res)
839-
end
840-
end
841-
842724
func from_call_array_to_call{
843725
syscall_ptr: felt*
844726
} (

contracts/utils/array.cairo

Lines changed: 0 additions & 22 deletions
This file was deleted.

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cairo-lang>=0.7.1
2-
cairo-nile
1+
cairo-lang>=0.8.1
2+
cairo-nile>=0.5.0
33
pytest
44
pytest-asyncio

test/address_registry.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import asyncio
33
from starkware.starknet.testing.starknet import Starknet
44
from utils.Signer import Signer
5-
from utils.deploy import deploy
5+
from utils.utilities import deploy, str_to_felt
66
from utils.TransactionSender import TransactionSender
77

88
signer = Signer(123456789987654321)
99
guardian = Signer(456789987654321123)
1010

11-
VERSION = 206933405232 # '0.1.0' = 30 2E 31 2E 30 = 0x302E312E30 = 206933405232
11+
VERSION = str_to_felt('0.2.1')
1212
L1_ADDRESS = 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984
1313

1414
@pytest.fixture(scope='module')
@@ -23,7 +23,8 @@ async def get_starknet():
2323
@pytest.fixture
2424
async def account_factory(get_starknet):
2525
starknet = get_starknet
26-
account = await deploy(starknet, "contracts/ArgentAccount.cairo", [signer.public_key, guardian.public_key])
26+
account = await deploy(starknet, "contracts/ArgentAccount.cairo")
27+
await account.initialize(signer.public_key, guardian.public_key).invoke()
2728
return account
2829

2930
@pytest.fixture
@@ -47,6 +48,6 @@ async def test_setup_registry(account_factory, registry_factory):
4748

4849
assert (await registry.get_L1_address(account.contract_address).call()).result.res == 0
4950

50-
await sender.send_transaction(registry.contract_address, 'set_L1_address', [L1_ADDRESS], [signer, guardian])
51+
await sender.send_transaction([(registry.contract_address, 'set_L1_address', [L1_ADDRESS])], [signer, guardian])
5152

5253
assert (await registry.get_L1_address(account.contract_address).call()).result.res == L1_ADDRESS

test/argent_account.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import asyncio
33
import logging
44
from starkware.starknet.testing.starknet import Starknet
5-
from starkware.starkware_utils.error_handling import StarkException
6-
from starkware.starknet.definitions.error_codes import StarknetErrorCode
7-
from starkware.starknet.business_logic.state import BlockInfo
8-
from starkware.starknet.compiler.compile import get_selector_from_name
5+
from starkware.starknet.business_logic.state.state import BlockInfo
96
from utils.Signer import Signer
107
from utils.utilities import deploy, assert_revert, str_to_felt, assert_event_emmited
118
from utils.TransactionSender import TransactionSender
@@ -22,7 +19,7 @@
2219
DEFAULT_TIMESTAMP = 1640991600
2320
ESCAPE_SECURITY_PERIOD = 24*7*60*60
2421

25-
VERSION = str_to_felt('0.2.0')
22+
VERSION = str_to_felt('0.2.1')
2623

2724
IACCOUNT_ID = 0xf10dbd44
2825

@@ -39,7 +36,7 @@ async def get_starknet():
3936
return starknet
4037

4138
def update_starknet_block(starknet, block_number=1, block_timestamp=DEFAULT_TIMESTAMP):
42-
starknet.state.state.block_info = BlockInfo(block_number=block_number, block_timestamp=block_timestamp)
39+
starknet.state.state.block_info = BlockInfo(block_number=block_number, block_timestamp=block_timestamp, gas_price=0)
4340

4441
def reset_starknet_block(starknet):
4542
update_starknet_block(starknet=starknet)

test/multicall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import asyncio
33
from starkware.starknet.testing.starknet import Starknet
44
from starkware.starknet.public.abi import get_selector_from_name
5-
from utils.utilities import deploy, str_to_felt, uint
5+
from utils.utilities import deploy, str_to_felt
66

77
user1 = 0x69221ff9023c4d7ba9123f0f9c32634c23fc5776d86657f464ecb51fd811445
88
user2 = 0x72648c3b1953572d2c4395a610f18b83cca14fa4d1ba10fc4484431fd463e5c

test/proxy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
import asyncio
33
from starkware.starknet.testing.starknet import Starknet
4-
from starkware.starkware_utils.error_handling import StarkException
54
from starkware.starknet.definitions.error_codes import StarknetErrorCode
65
from utils.Signer import Signer
76
from utils.utilities import deploy, deploy_proxy, assert_revert, str_to_felt, assert_event_emmited
@@ -12,7 +11,7 @@
1211
wrong_signer = Signer(666666666666666666)
1312
wrong_guardian = Signer(6767676767)
1413

15-
VERSION = str_to_felt('0.2.0')
14+
VERSION = str_to_felt('0.2.1')
1615

1716
@pytest.fixture(scope='module')
1817
def event_loop():

test/struct_hash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
import asyncio
33
from starkware.starknet.testing.starknet import Starknet
4-
from utils.deploy import deploy
4+
from utils.utilities import deploy
55

66
user1 = 0x69221ff9023c4d7ba9123f0f9c32634c23fc5776d86657f464ecb51fd811445
77
user2 = 0x72648c3b1953572d2c4395a610f18b83cca14fa4d1ba10fc4484431fd463e5c

0 commit comments

Comments
 (0)