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

Cairo 2.6.3 + OZ 0.10 #371

Merged
merged 17 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/actions/install-cairo/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ description: A composite action that installs cairo and scarb binaries
inputs:
cairo_version:
description: Cairo release version
default: "v2.5.4"
default: "v2.6.3"
required: false
scarb_version:
description: Scarb release version
default: "v2.5.4"
default: "v2.6.3"
required: false

runs:
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/install-starknet-foundry/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A composite action that installs the snforge and sncast binaries
inputs:
starknet_foundry_version:
description: Starknet Foundry release version
default: "0.18.0"
default: "0.19.0"
required: false

runs:
Expand Down
4 changes: 2 additions & 2 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ dependencies = [

[[package]]
name = "openzeppelin"
version = "0.9.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.9.0#364db5b1aecc1335d2e65db887291d19aa28937d"
version = "0.10.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3"
5 changes: 3 additions & 2 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "chainlink"
version = "0.1.0"
cairo-version = "2.6.3"
description = "Chainlink contracts for Starknet"
homepage = "https://github.com/smartcontractkit/chainlink-starknet"

Expand All @@ -11,8 +12,8 @@ sierra = "cairo-compile . -r"
# Uncomment if you want to use dependencies
# Note: currently testing doesn't work with dependencies
[dependencies]
starknet = ">=1.3.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.9.0" }
starknet = ">=2.6.3"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }

[lib]

Expand Down
2 changes: 1 addition & 1 deletion contracts/src/access_control/access_controller.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod AccessController {
use starknet::ContractAddress;
use starknet::class_hash::ClassHash;

use openzeppelin::access::ownable::ownable::OwnableComponent;
use openzeppelin::access::ownable::OwnableComponent;

use chainlink::libraries::access_control::{AccessControlComponent, IAccessController};
use chainlink::libraries::type_and_version::ITypeAndVersion;
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/emergency/sequencer_uptime_feed.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod SequencerUptimeFeed {
use option::OptionTrait;
use zeroable::Zeroable;

use openzeppelin::access::ownable::ownable::OwnableComponent;
use openzeppelin::access::ownable::OwnableComponent;

use chainlink::libraries::access_control::{AccessControlComponent, IAccessController};
use chainlink::libraries::access_control::AccessControlComponent::InternalTrait as AccessControlInternalTrait;
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/libraries/access_control.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod AccessControlComponent {
use starknet::class_hash::ClassHash;
use zeroable::Zeroable;

use openzeppelin::access::ownable::ownable::OwnableComponent;
use openzeppelin::access::ownable::OwnableComponent;

use OwnableComponent::InternalImpl as OwnableInternalImpl;

Expand Down
138 changes: 59 additions & 79 deletions contracts/src/ocr2/aggregator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ mod Aggregator {
use starknet::storage_address_from_base_and_offset;
use starknet::class_hash::ClassHash;

use openzeppelin::access::ownable::ownable::OwnableComponent;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::token::erc20::interface::{IERC20, IERC20Dispatcher, IERC20DispatcherTrait};

use chainlink::utils::split_felt;
Expand Down Expand Up @@ -603,37 +603,31 @@ mod Aggregator {
) {
let mut index = 0;
let mut span = oracles.span();
loop {
match span.pop_front() {
Option::Some(oracle) => {
// NOTE: index should start with 1 here because storage is 0-initialized.
// That way signers(pkey) => 0 indicates "not present"
// This is why we increment first, before using the index
index += 1;

// check for duplicates
let existing_signer = self._signers.read(*oracle.signer);
assert(existing_signer == 0_usize, 'repeated signer');

let existing_transmitter = self._transmitters.read(*oracle.transmitter);
assert(existing_transmitter.index == 0_usize, 'repeated transmitter');

self._signers.write(*oracle.signer, index);
self._signers_list.write(index, *oracle.signer);

self
._transmitters
.write(*oracle.transmitter, Oracle { index, payment_juels: 0_u128 });
self._transmitters_list.write(index, *oracle.transmitter);

self._reward_from_aggregator_round_id.write(index, latest_round_id);
},
Option::None(_) => {
self._oracles_len.write(index);
break ();
}
while let Option::Some(oracle) = span
.pop_front() {
// NOTE: index should start with 1 here because storage is 0-initialized.
// That way signers(pkey) => 0 indicates "not present"
// This is why we increment first, before using the index
index += 1;

// check for duplicates
let existing_signer = self._signers.read(*oracle.signer);
assert(existing_signer == 0_usize, 'repeated signer');

let existing_transmitter = self._transmitters.read(*oracle.transmitter);
assert(existing_transmitter.index == 0_usize, 'repeated transmitter');

self._signers.write(*oracle.signer, index);
self._signers_list.write(index, *oracle.signer);

self
._transmitters
.write(*oracle.transmitter, Oracle { index, payment_juels: 0_u128 });
self._transmitters_list.write(index, *oracle.transmitter);

self._reward_from_aggregator_round_id.write(index, latest_round_id);
};
}
self._oracles_len.write(index);
}
}

Expand Down Expand Up @@ -821,29 +815,22 @@ mod Aggregator {
mut signed_count: u128
) {
let mut span = signatures.span();
loop {
match span.pop_front() {
Option::Some(signature) => {
let index = self._signers.read(*signature.public_key);
assert(index != 0_usize, 'invalid signer'); // 0 index == uninitialized

let indexed_bit = pow(2_u128, index.into() - 1_u128);
let prev_signed_count = signed_count;
signed_count = signed_count | indexed_bit;
assert(prev_signed_count != signed_count, 'duplicate signer');

let is_valid = ecdsa::check_ecdsa_signature(
msg, *signature.public_key, *signature.r, *signature.s
);
while let Option::Some(signature) = span
.pop_front() {
let index = self._signers.read(*signature.public_key);
assert(index != 0_usize, 'invalid signer'); // 0 index == uninitialized

assert(is_valid, '');
},
Option::None(_) => {
// No more signatures left!
break ();
}
let indexed_bit = pow(2_u128, index.into() - 1_u128);
let prev_signed_count = signed_count;
signed_count = signed_count | indexed_bit;
assert(prev_signed_count != signed_count, 'duplicate signer');

let is_valid = ecdsa::check_ecdsa_signature(
msg, *signature.public_key, *signature.r, *signature.s
);

assert(is_valid, '');
};
};
}
}

Expand Down Expand Up @@ -1179,33 +1166,26 @@ mod Aggregator {
impl PayeeManagementImpl of super::PayeeManagement<ContractState> {
fn set_payees(ref self: ContractState, mut payees: Array<PayeeConfig>) {
self.ownable.assert_only_owner();
loop {
match payees.pop_front() {
Option::Some(payee) => {
let current_payee = self._payees.read(payee.transmitter);
let is_unset = current_payee.is_zero();
let is_same = current_payee == payee.payee;
assert(is_unset | is_same, 'payee already set');

self._payees.write(payee.transmitter, payee.payee);

self
.emit(
Event::PayeeshipTransferred(
PayeeshipTransferred {
transmitter: payee.transmitter,
previous: current_payee,
current: payee.payee
}
)
);
},
Option::None(_) => {
// No more payees left!
break ();
}
};
}
while let Option::Some(payee) = payees
.pop_front() {
let current_payee = self._payees.read(payee.transmitter);
let is_unset = current_payee.is_zero();
let is_same = current_payee == payee.payee;
assert(is_unset | is_same, 'payee already set');

self._payees.write(payee.transmitter, payee.payee);

self
.emit(
Event::PayeeshipTransferred(
PayeeshipTransferred {
transmitter: payee.transmitter,
previous: current_payee,
current: payee.payee
}
)
);
}
}

fn transfer_payeeship(
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/ocr2/aggregator_proxy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod AggregatorProxy {
use starknet::storage_address_from_base_and_offset;
use starknet::class_hash::ClassHash;

use openzeppelin::access::ownable::ownable::OwnableComponent;
use openzeppelin::access::ownable::OwnableComponent;

use chainlink::ocr2::aggregator::IAggregator;
use chainlink::ocr2::aggregator::Round;
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/tests/test_link_token.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ fn test_constructor() {
LinkToken::constructor(ref state, sender, sender);

assert(LinkToken::minter(@state) == sender, 'minter valid');
assert(state.erc20.name() == 'ChainLink Token', 'name valid');
assert(state.erc20.symbol() == 'LINK', 'symbol valid');
assert(state.erc20.name() == "ChainLink Token", 'name valid');
assert(state.erc20.symbol() == "LINK", 'symbol valid');
}

#[test]
Expand Down
Loading
Loading