Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate UDC #919

Merged
merged 41 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5894303
add udc preset
andrew-fleming Feb 18, 2024
48a72ac
add udc preset class hash
andrew-fleming Feb 18, 2024
f094ff6
tidy up code
andrew-fleming Feb 21, 2024
e135b1a
add entry to changelog
andrew-fleming Feb 21, 2024
b078f70
tidy up code
andrew-fleming Feb 21, 2024
90b542f
clean up code
andrew-fleming Feb 21, 2024
476e058
add udc impl
andrew-fleming Feb 21, 2024
e78867c
add deployment check and comments
andrew-fleming Feb 21, 2024
b343394
Apply suggestions from code review
andrew-fleming Feb 23, 2024
5215030
add comments
andrew-fleming Feb 24, 2024
d81c544
move IUniversalDeployer to interface mod in udc dir
andrew-fleming Feb 24, 2024
40b293a
fix conflicts, add PartialEq to udc event
andrew-fleming Mar 6, 2024
c645eca
fix conflicts
andrew-fleming Mar 6, 2024
620d22b
update changelog
andrew-fleming Mar 6, 2024
5324daa
remove duplicate entry
andrew-fleming Mar 6, 2024
2bbb194
Apply suggestions from code review
andrew-fleming Mar 11, 2024
8b0bf42
fix from_zero logic
andrew-fleming Mar 11, 2024
fb741dc
remove member names from struct
andrew-fleming Mar 11, 2024
8ee0297
abstract event assertions into fn
andrew-fleming Mar 11, 2024
b6d1e3f
fix formatting
andrew-fleming Mar 11, 2024
fbe27e0
Update src/tests/presets/test_universal_deployer.cairo
andrew-fleming Mar 12, 2024
22e4779
update assertion fn
andrew-fleming Mar 12, 2024
64f04fe
fix conflicts
andrew-fleming Mar 14, 2024
1569954
Update src/presets/universal_deployer.cairo
andrew-fleming Mar 15, 2024
db5f13d
use poseidon in udc
andrew-fleming Mar 19, 2024
c1de6e0
fix formatting
andrew-fleming Mar 19, 2024
a924bf5
Merge branch 'main' into add-udc
andrew-fleming Mar 19, 2024
05a6fa2
fix spdx
andrew-fleming Mar 19, 2024
baa6a11
Merge branch 'add-udc' of https://github.com/andrew-fleming/cairo-con…
andrew-fleming Mar 19, 2024
f25a3c1
Apply suggestions from code review
andrew-fleming Mar 19, 2024
f38a5a6
fix from_zero conflicts, change poseidon use, update tests
andrew-fleming Mar 19, 2024
14fc5be
fix formatting
andrew-fleming Mar 19, 2024
8e474a1
remove deployment info from comment
andrew-fleming Mar 19, 2024
f8da011
change code reference in comment
andrew-fleming Mar 20, 2024
036500e
Apply suggestions from code review
andrew-fleming Mar 22, 2024
b1c86c5
fix formatting
andrew-fleming Mar 22, 2024
1aa212d
fix from_zero var in event test
andrew-fleming Mar 22, 2024
564f0c8
Apply suggestions from code review
andrew-fleming Mar 22, 2024
bca3301
update HashTrait in test
andrew-fleming Mar 22, 2024
7bfdef6
fix conflicts
andrew-fleming Mar 22, 2024
d91c61d
fix conflicts
andrew-fleming Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 2 additions & 17 deletions src/presets/universal_deployer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,16 @@ mod UniversalDeployer {
calldata: Span<felt252>
) -> ContractAddress {
let deployer: ContractAddress = get_caller_address();

// Defaults for non-unique deployment
let mut _salt: felt252 = salt;
let from_zero: bool = !unique;

let mut _salt: felt252 = salt;
if unique {
_salt = pedersen(deployer.into(), salt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider using poseidon since is much cheaper? Maybe a UDC_v2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge +1 to UDC_v2 with poseidon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, but note this UDC is already v2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may need to be explicit in the name regarding the version. If people are using UDC already to predict addresses before deployment, getting confused about whether it uses pedersen or poseidon could be problematic, since the addresses would be different.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update to Poseidon then on this PR? And should we add documentation about it and versions? In the starknet docsite we are not for example mentioning which hash algorithm is used, or how to precompute the addresses, and I think that's worth to mention.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this an issue: #950

from_zero = false;
}

let (address, _) = starknet::deploy_syscall(class_hash, _salt, calldata, from_zero)
.unwrap_syscall();

self
.emit(
ContractDeployed {
address: address,
deployer: deployer,
unique: unique,
class_hash: class_hash,
calldata: calldata,
salt: salt
}
);

self.emit(ContractDeployed { address, deployer, unique, class_hash, calldata, salt });
return address;
}
}
Expand Down
57 changes: 33 additions & 24 deletions src/tests/presets/test_universal_deployer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,15 @@ fn test_deploy_not_unique() {
assert_eq!(expected_addr, deployed_addr);

// Check event
let event = utils::pop_log::<UniversalDeployer::Event>(udc.contract_address).unwrap();
let expected = UniversalDeployer::Event::ContractDeployed(
ContractDeployed {
address: deployed_addr,
deployer: CALLER(),
unique: unique,
class_hash: ERC20_CLASS_HASH(),
calldata: ERC20_CALLDATA(),
salt: SALT
}
assert_event_contract_deployed(
udc.contract_address,
deployed_addr,
CALLER(),
unique,
ERC20_CLASS_HASH(),
ERC20_CALLDATA(),
SALT
);
assert!(event == expected);
utils::assert_no_events_left(udc.contract_address);

// Check deployment
let erc20 = IERC20Dispatcher { contract_address: deployed_addr };
Expand All @@ -88,19 +84,15 @@ fn test_deploy_unique() {
assert_eq!(expected_addr, deployed_addr);

// Check event
let event = utils::pop_log::<UniversalDeployer::Event>(udc.contract_address).unwrap();
let expected = UniversalDeployer::Event::ContractDeployed(
ContractDeployed {
address: deployed_addr,
deployer: CALLER(),
unique: unique,
class_hash: ERC20_CLASS_HASH(),
calldata: ERC20_CALLDATA(),
salt: SALT
}
assert_event_contract_deployed(
udc.contract_address,
deployed_addr,
CALLER(),
unique,
ERC20_CLASS_HASH(),
ERC20_CALLDATA(),
SALT
);
assert!(event == expected);
utils::assert_no_events_left(udc.contract_address);

// Check deployment
let erc20 = IERC20Dispatcher { contract_address: deployed_addr };
Expand Down Expand Up @@ -150,3 +142,20 @@ fn calculate_contract_address_from_hash(
let felt_addr = u256_addr.try_into().unwrap();
starknet::contract_address_try_from_felt252(felt_addr).unwrap()
}

fn assert_event_contract_deployed(
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved
contract: ContractAddress,
address: ContractAddress,
deployer: ContractAddress,
unique: bool,
class_hash: ClassHash,
calldata: Span<felt252>,
salt: felt252
) {
let event = utils::pop_log::<UniversalDeployer::Event>(contract).unwrap();
let expected = UniversalDeployer::Event::ContractDeployed(
ContractDeployed { address, deployer, unique, class_hash, calldata, salt }
);
assert!(event == expected);
utils::assert_no_events_left(contract);
}