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 #610

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
33dada9
update cairo
andrew-fleming Apr 18, 2023
503e72d
update Cargo
andrew-fleming Apr 18, 2023
3d3f8f9
fix test command
andrew-fleming Apr 18, 2023
59a7aa1
fix formatting
andrew-fleming Apr 18, 2023
e0ae838
add utils and udc
andrew-fleming Apr 18, 2023
bb77b8d
update cairo
andrew-fleming Apr 18, 2023
a078431
remove comment
andrew-fleming Apr 18, 2023
ef593d0
remove trailing comma
andrew-fleming Apr 18, 2023
ab57f1e
clean up contract
andrew-fleming Apr 26, 2023
80b1937
set cairo to alpha7
andrew-fleming Apr 28, 2023
fcec061
set Cargo
andrew-fleming Apr 28, 2023
f0e960b
merge cairo-1 and fix conflicts
andrew-fleming Apr 28, 2023
e367a27
use address zeroable
andrew-fleming Apr 28, 2023
25b72e6
fix expected syntax
andrew-fleming Apr 28, 2023
28e8759
fix conflict
andrew-fleming Apr 28, 2023
9f39597
update cairo
andrew-fleming Apr 28, 2023
b2c05a4
remove comment
andrew-fleming Apr 28, 2023
5318f6b
remove unused import
andrew-fleming Apr 28, 2023
c65161c
update cairo to rc0
andrew-fleming May 6, 2023
4cb9584
update Cargo
andrew-fleming May 6, 2023
88b0e3d
simplify imports
andrew-fleming May 6, 2023
2c9121b
Merge branch 'cairo-1' into cairo1-udc
andrew-fleming May 6, 2023
8b2e1d4
remove duplicate import
andrew-fleming May 6, 2023
695b16d
Apply suggestions from code review
andrew-fleming May 11, 2023
553f667
bump cairo
andrew-fleming May 15, 2023
362f688
rename, add SpanSerde, add underscore to calldata
andrew-fleming May 15, 2023
1873990
fix udc name
andrew-fleming May 15, 2023
4c6d61c
fix erc20 abi
andrew-fleming May 15, 2023
c909d46
add test draft
andrew-fleming May 15, 2023
d5c1ed4
fix formatting
andrew-fleming May 15, 2023
6eca688
remove print
andrew-fleming May 15, 2023
390488c
fix imports
andrew-fleming May 15, 2023
0cf47b9
Merge branch 'cairo-1' into cairo1-udc
andrew-fleming May 22, 2023
b23e1ef
simplify import
andrew-fleming May 23, 2023
f5a65fa
add compute_hash and address calculation
andrew-fleming Jun 2, 2023
bf1669f
fix conflicts
andrew-fleming Jun 2, 2023
aac54f1
change array to span
andrew-fleming Jun 2, 2023
f3bc0f5
integrate calculate address to tests
andrew-fleming Jun 2, 2023
5553241
clean up code
andrew-fleming Jun 2, 2023
014c412
fix conflicts
andrew-fleming Jul 17, 2023
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
699 changes: 334 additions & 365 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ members = [
]

[workspace.package]
version = "1.0.0-alpha.6"
version = "1.0.0-alpha.7"
edition = "2021"
repository = "https://github.com/starkware-libs/cairo/"
license = "Apache-2.0"
Expand All @@ -43,9 +43,8 @@ ark-ff = "0.4.0-alpha.7"
ark-std = "0.3.0"
assert_matches = "1.5"
bimap = "0.6.2"
cairo-felt = "0.1.1"
cairo-vm = "0.1.2"
chrono = "0.4.23"
cairo-felt = "0.3.0-rc1"
cairo-vm = "0.3.0-rc1"
clap = { version = "4.0", features = ["derive"] }
colored = "2"
const-fnv1a-hash = "1.1.0"
Expand All @@ -57,16 +56,16 @@ genco = "0.17.0"
good_lp = { version = "1.3.2", features = ["minilp"], default-features = false }
id-arena = "2.2.1"
ignore = "0.4.20"
indexmap = "1.9.1"
indoc = "1.0.7"
indexmap = { version = "1.9.1", features = ["serde"] }
indoc = "2.0.1"
itertools = "0.10.3"
lalrpop-util = { version = "0.19.8", features = ["lexer"] }
lazy_static = "1.4.0"
lalrpop-util = { version = "0.19.9", features = ["lexer"] }
log = "0.4"
lsp = { version = "0.93", package = "lsp-types" }
num-bigint = "0.4"
num-integer = "0.1"
num-traits = "0.2"
once_cell = "1.17.1"
path-clean = "0.1.0"
pretty_assertions = "1.2.1"
proc-macro2 = "1.0"
Expand All @@ -78,12 +77,13 @@ scarb-metadata = "1.0.1"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0"
sha3 = "0.10.6"
smol_str = "0.1.23"
smol_str = { version = "0.2.0", features = ["serde"] }
syn = { version = "1.0.99", features = ["full", "extra-traits"] }
test-case = "2.2.2"
test-case-macros = "2.2.2"
test-log = "0.2.11"
thiserror = "1.0.32"
time = { version = "0.3.20", features = ["formatting", "macros", "local-offset"] }
tokio = { version = "1.18.2", features = ["full", "sync"] }
toml = "0.4.2"
tower-lsp = "0.17.0"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build:
cargo build

test:
cargo run --bin cairo-test -- --starknet --path $(SOURCE_FOLDER)
cargo run --bin cairo-test -- --starknet $(SOURCE_FOLDER)

format:
cargo run --bin cairo-format -- --recursive $(SOURCE_FOLDER) --print-parsing-errors
Expand Down
2 changes: 1 addition & 1 deletion cairo
Submodule cairo updated 582 files
1 change: 1 addition & 0 deletions src/openzeppelin/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod security;
mod token;
mod utils;
mod tests;
2 changes: 1 addition & 1 deletion src/openzeppelin/security/initializable.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[contract]
mod Initializable {
struct Storage {
initialized: bool,
initialized: bool
}

#[internal]
Expand Down
2 changes: 1 addition & 1 deletion src/openzeppelin/security/pausable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod Pausable {
use starknet::get_caller_address;

struct Storage {
paused: bool,
paused: bool
}

#[event]
Expand Down
32 changes: 16 additions & 16 deletions src/openzeppelin/tests/test_erc20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn test_approve() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: approve from 0', ))]
#[should_panic(expected: ('ERC20: approve from 0', ))]
fn test_approve_from_zero() {
let (owner, supply) = setup();
let spender: ContractAddress = contract_address_const::<2>();
Expand All @@ -97,7 +97,7 @@ fn test_approve_from_zero() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: approve to 0', ))]
#[should_panic(expected: ('ERC20: approve to 0', ))]
fn test_approve_to_zero() {
let (owner, supply) = setup();
let spender: ContractAddress = contract_address_const::<0>();
Expand All @@ -120,7 +120,7 @@ fn test__approve() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: approve from 0', ))]
#[should_panic(expected: ('ERC20: approve from 0', ))]
fn test__approve_from_zero() {
let owner: ContractAddress = contract_address_const::<0>();
let spender: ContractAddress = contract_address_const::<1>();
Expand All @@ -130,7 +130,7 @@ fn test__approve_from_zero() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: approve to 0', ))]
#[should_panic(expected: ('ERC20: approve to 0', ))]
fn test__approve_to_zero() {
let (owner, supply) = setup();

Expand Down Expand Up @@ -170,7 +170,7 @@ fn test__transfer() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('u256_sub Overflow', ))]
#[should_panic(expected: ('u256_sub Overflow', ))]
fn test__transfer_not_enough_balance() {
let (sender, supply) = setup();

Expand All @@ -181,7 +181,7 @@ fn test__transfer_not_enough_balance() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: transfer from 0', ))]
#[should_panic(expected: ('ERC20: transfer from 0', ))]
fn test__transfer_from_zero() {
let sender: ContractAddress = contract_address_const::<0>();
let recipient: ContractAddress = contract_address_const::<1>();
Expand All @@ -191,7 +191,7 @@ fn test__transfer_from_zero() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: transfer to 0', ))]
#[should_panic(expected: ('ERC20: transfer to 0', ))]
fn test__transfer_to_zero() {
let (sender, supply) = setup();

Expand Down Expand Up @@ -245,7 +245,7 @@ fn test_transfer_from_doesnt_consume_infinite_allowance() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('u256_sub Overflow', ))]
#[should_panic(expected: ('u256_sub Overflow', ))]
fn test_transfer_from_greater_than_allowance() {
let (owner, supply) = setup();

Expand All @@ -263,7 +263,7 @@ fn test_transfer_from_greater_than_allowance() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: transfer to 0', ))]
#[should_panic(expected: ('ERC20: transfer to 0', ))]
fn test_transfer_from_to_zero_address() {
let (owner, supply) = setup();

Expand All @@ -280,7 +280,7 @@ fn test_transfer_from_to_zero_address() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('u256_sub Overflow', ))]
#[should_panic(expected: ('u256_sub Overflow', ))]
fn test_transfer_from_from_zero_address() {
let (owner, supply) = setup();

Expand Down Expand Up @@ -312,7 +312,7 @@ fn test_increase_allowance() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: approve to 0', ))]
#[should_panic(expected: ('ERC20: approve to 0', ))]
fn test_increase_allowance_to_zero_address() {
let (owner, supply) = setup();

Expand All @@ -324,7 +324,7 @@ fn test_increase_allowance_to_zero_address() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: approve from 0', ))]
#[should_panic(expected: ('ERC20: approve from 0', ))]
fn test_increase_allowance_from_zero_address() {
let (owner, supply) = setup();

Expand Down Expand Up @@ -355,7 +355,7 @@ fn test_decrease_allowance() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('u256_sub Overflow', ))]
#[should_panic(expected: ('u256_sub Overflow', ))]
fn test_decrease_allowance_to_zero_address() {
let (owner, supply) = setup();

Expand All @@ -367,7 +367,7 @@ fn test_decrease_allowance_to_zero_address() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('u256_sub Overflow', ))]
#[should_panic(expected: ('u256_sub Overflow', ))]
fn test_decrease_allowance_from_zero_address() {
let (owner, supply) = setup();

Expand Down Expand Up @@ -423,7 +423,7 @@ fn test__mint() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: mint to 0', ))]
#[should_panic(expected: ('ERC20: mint to 0', ))]
fn test__mint_to_zero() {
let minter: ContractAddress = contract_address_const::<0>();
let amount: u256 = u256_from_felt252(100);
Expand All @@ -445,7 +445,7 @@ fn test__burn() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('ERC20: burn from 0', ))]
#[should_panic(expected: ('ERC20: burn from 0', ))]
fn test__burn_from_zero() {
setup();
let zero_address: ContractAddress = contract_address_const::<0>();
Expand Down
6 changes: 3 additions & 3 deletions src/openzeppelin/tests/test_initializable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use openzeppelin::security::initializable::Initializable;
#[test]
#[available_gas(2000000)]
fn test_initialize() {
assert(!Initializable::is_initialized(),'Should not be initialized');
assert(!Initializable::is_initialized(), 'Should not be initialized');
Initializable::initialize();
assert(Initializable::is_initialized(),'Should be initialized');
assert(Initializable::is_initialized(), 'Should be initialized');
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('Contract already initialized', ))]
#[should_panic(expected: ('Contract already initialized', ))]
fn test_initialize_when_initialized() {
Initializable::initialize();
Initializable::initialize();
Expand Down
12 changes: 6 additions & 6 deletions src/openzeppelin/tests/test_pausable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use openzeppelin::tests::mocks::mock_pausable::MockPausable;
#[test]
#[available_gas(2000000)]
fn test_pause_when_unpaused() {
assert(! MockPausable::is_paused(), 'Should not be paused');
assert(!MockPausable::is_paused(), 'Should not be paused');
assert(MockPausable::get_count() == 0, 'Should be 0');
MockPausable::assert_unpaused_and_increment();
assert(MockPausable::get_count() == 1, 'Should increment');
Expand All @@ -13,15 +13,15 @@ fn test_pause_when_unpaused() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('Pausable: paused', ))]
#[should_panic(expected: ('Pausable: paused', ))]
fn test_pause_when_paused() {
MockPausable::pause();
MockPausable::pause();
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('Pausable: paused', ))]
#[should_panic(expected: ('Pausable: paused', ))]
fn test_pause_increment() {
MockPausable::pause();
MockPausable::assert_unpaused_and_increment();
Expand All @@ -33,15 +33,15 @@ fn test_unpause_when_paused() {
MockPausable::pause();
assert(MockPausable::is_paused(), 'Should be paused');
MockPausable::unpause();
assert(! MockPausable::is_paused(), 'Should not be paused');
assert(!MockPausable::is_paused(), 'Should not be paused');
MockPausable::assert_unpaused_and_increment();
assert(MockPausable::get_count() == 1, 'Should increment');
}

#[test]
#[available_gas(2000000)]
#[should_panic(expected = ('Pausable: not paused', ))]
#[should_panic(expected: ('Pausable: not paused', ))]
fn test_unpause_when_unpaused() {
assert(! MockPausable::is_paused(), 'Should be unpaused');
assert(!MockPausable::is_paused(), 'Should be unpaused');
MockPausable::unpause();
}
1 change: 0 additions & 1 deletion src/openzeppelin/token/erc20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mod ERC20 {
use openzeppelin::token::erc20::IERC20;
use starknet::get_caller_address;
use starknet::ContractAddress;
use starknet::ContractAddressZeroable;
use zeroable::Zeroable;

struct Storage {
Expand Down
1 change: 1 addition & 0 deletions src/openzeppelin/utils.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod udc;
martriay marked this conversation as resolved.
Show resolved Hide resolved
64 changes: 64 additions & 0 deletions src/openzeppelin/utils/udc.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use starknet::class_hash::ClassHash;
use starknet::ContractAddress;

// TODO: Fix trait impl errors in abi
// #[abi]
trait IUniversalDeployerContract {
#[event]
Copy link
Contributor

Choose a reason for hiding this comment

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

can you do these modifiers on traits like this?
i haven't seen that anywhere else yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, you can and the contracts compile. The external and view macros might be redundant, but I assume we'll need to include it for event (so other contracts aren't required to reimplement the event in an impl). Here's a test data example from the Cairo repo: https://github.com/starkware-libs/cairo/blob/main/crates/cairo-lang-starknet/src/plugin/plugin_test_data/dispatcher#L6-L17

fn ContractDeployed(
address: ContractAddress,
deployer: ContractAddress,
unique: bool,
class_hash: ClassHash,
calldata: Array<felt252>,
salt: felt252,
);
#[external]
fn deploy_contract(
class_hash: ClassHash, salt: felt252, unique: bool, calldata: Array<felt252>
) -> ContractAddress;
}

#[contract]
mod UniversalDeployerContract {
use array::ArrayTrait;
use hash::pedersen;
use starknet::class_hash::ClassHash;
use starknet::ContractAddress;
use starknet::get_caller_address;
use traits::Into;

#[event]
fn ContractDeployed(
address: ContractAddress,
deployer: ContractAddress,
unique: bool,
class_hash: ClassHash,
calldata: Array<felt252>,
salt: felt252,
) {}

#[external]
fn deploy_contract(
class_hash: ClassHash, salt: felt252, unique: bool, calldata: Array<felt252>
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved
) -> ContractAddress {
let deployer: ContractAddress = get_caller_address();

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

if unique {
_salt = pedersen(deployer.into(), salt);
from_zero = false;
}

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

ContractDeployed(address, deployer, unique, class_hash, calldata, salt);

return address;
}
}