Skip to content

Commit

Permalink
Merge branch 'develop' into augustus.BCI-1224.rewrite-example-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds authored Jun 6, 2023
2 parents a5ea6c1 + 62ee8f9 commit cfc12c8
Show file tree
Hide file tree
Showing 99 changed files with 2,588 additions and 1,747 deletions.
2 changes: 2 additions & 0 deletions .github/actions/build-test-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ inputs:
runs:
using: composite
steps:
- name: Install Cairo
uses: ./.github/actions/install-cairo
- name: Check if image exists
id: check-image
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@8489879838862929f43f7d7cd1b33903965cf507 # v2.1.6
Expand Down
14 changes: 8 additions & 6 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: "v1.0.0-rc0"
default: "v1.0.0"
required: false
scarb_version:
description: Scarb release version
default: "v0.2.0-alpha.1"
default: "v0.2.1"
required: false

runs:
Expand All @@ -20,12 +20,14 @@ runs:
run: |
wget https://github.com/starkware-libs/cairo/releases/download/${{ inputs.cairo_version }}/release-x86_64-unknown-linux-musl.tar.gz
tar -xvzf release-x86_64-unknown-linux-musl.tar.gz
echo "$GITHUB_WORKSPACE/cairo/bin" >> $GITHUB_PATH
mv -vf cairo cairo-build
echo "$GITHUB_WORKSPACE/cairo-build/bin" >> $GITHUB_PATH
- name: Setup Scarb for Linux
id: install-scarb
shell: bash
run: |
wget https://github.com/software-mansion/scarb/releases/download/${{ inputs.scarb_version }}/scarb-${{ inputs.scarb_version }}-x86_64-unknown-linux-gnu.tar.gz
tar -xvzf scarb-${{ inputs.scarb_version }}-x86_64-unknown-linux-gnu.tar.gz
echo "$GITHUB_WORKSPACE/scarb-${{ inputs.scarb_version }}-x86_64-unknown-linux-gnu/bin" >> $GITHUB_PATH
wget https://github.com/software-mansion/scarb/releases/download/${{ inputs.scarb_version }}/scarb-${{ inputs.scarb_version }}-x86_64-unknown-linux-musl.tar.gz
tar -xvzf scarb-${{ inputs.scarb_version }}-x86_64-unknown-linux-musl.tar.gz
mv -vf scarb-${{ inputs.scarb_version }}-x86_64-unknown-linux-musl scarb-build
echo "$GITHUB_WORKSPACE/scarb-build/bin" >> $GITHUB_PATH
5 changes: 3 additions & 2 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- name: Install Cairo
uses: ./.github/actions/install-cairo

- name: Install starknet-devnet (via venv+pip)
run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt

- name: Test
run: nix develop -c make test-ts-contracts

Expand All @@ -32,8 +35,6 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
with:
submodules: 'recursive'

- name: Install Nix
uses: cachix/install-nix-action@5c11eae19dba042788936d4f1c9685fdd814ac49 # v19
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/integration-tests-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ jobs:
- name: Collect Metrics
if: always()
id: collect-gha-metrics
uses: smartcontractkit/push-gha-metrics-action@808c183d1f5c26a4f3fd50b75d3cf7b58d9aa293
uses: smartcontractkit/push-gha-metrics-action@90fcbaac8ebf86da9c4d55dba24f6fe3029f0e0b
with:
basic-auth: ${{ secrets.GRAFANA_CLOUD_BASIC_AUTH }}
hostname: ${{ secrets.GRAFANA_CLOUD_HOST }}
this-job-name: Build Custom CL Image
continue-on-error: true
- name: Check if image exists
id: check-image
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@8489879838862929f43f7d7cd1b33903965cf507 # v2.1.6
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@2c9f401149f6c25fb632067b7e6626aebeee5d69 # v2.1.6
with:
repository: chainlink
tag: starknet.${{ github.sha }}
Expand All @@ -50,10 +50,10 @@ jobs:
- name: Build Image
if: steps.check-image.outputs.exists == 'false'
# note using a temporary commit for build-image that works around the go get issues, replace when go get issues are fixed please
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/build-image@3ec816fe2e6dd3f70511e8115d86e296818c58f8 # cosmos_one_off
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/build-image@2c9f401149f6c25fb632067b7e6626aebeee5d69
with:
cl_repo: smartcontractkit/chainlink
cl_ref: 6b935c6ff7ec12b16b3f644b64080dec29b5a2c4
cl_ref: ${{ github.event.inputs.cl_branch_ref }}
# commit of the caller branch
dep_starknet_sha: ${{ github.event.pull_request.head.sha || github.sha }}
push_tag: ${{ env.CL_ECR }}:starknet.${{ github.sha }}
Expand Down Expand Up @@ -102,7 +102,8 @@ jobs:
TEST_ARGS: -test.timeout 1h
PRIVATE_KEY: ${{ secrets.GOERLI_PRIVATE_KEY }}
ACCOUNT: ${{ secrets.GOERLI_ACCOUNT }}
TTL: 1h
TTL: 3h
TEST_DURATION: 15m
NODE_COUNT: 5
permissions:
checks: write
Expand All @@ -113,7 +114,7 @@ jobs:
- name: Collect Metrics
if: always()
id: collect-gha-metrics
uses: smartcontractkit/push-gha-metrics-action@808c183d1f5c26a4f3fd50b75d3cf7b58d9aa293
uses: smartcontractkit/push-gha-metrics-action@8163dcea2f01a0a8fec84b284406ff7af1d2e1c0
with:
basic-auth: ${{ secrets.GRAFANA_CLOUD_BASIC_AUTH }}
hostname: ${{ secrets.GRAFANA_CLOUD_HOST }}
Expand All @@ -126,7 +127,7 @@ jobs:
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run Tests
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@8489879838862929f43f7d7cd1b33903965cf507 # v2.1.6
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@2c9f401149f6c25fb632067b7e6626aebeee5d69
with:
test_command_to_run: nix develop -c make test-integration-smoke-ci
test_download_vendor_packages_command: cd integration-tests && nix develop -c go mod download
Expand Down
26 changes: 18 additions & 8 deletions .github/workflows/integration-tests-soak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@ on:
required: true
default: 72h
type: string


test_duration:
description: Duration of soak
required: true
default: 72h
type: string
private_key:
description: Private key, ignore for devnet
required: false
type: string
account:
description: Account address, ignore for devnet
required: false

# Only run 1 of this workflow at a time per PR
concurrency:
Expand All @@ -48,16 +58,15 @@ jobs:
steps:
- name: Check if image exists
id: check-image
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@8489879838862929f43f7d7cd1b33903965cf507 # v2.1.6
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@2c9f401149f6c25fb632067b7e6626aebeee5d69 # v2.1.6
with:
repository: chainlink
tag: starknet.${{ github.sha }}
AWS_REGION: ${{ secrets.QA_AWS_REGION }}
AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
- name: Build Image
if: steps.check-image.outputs.exists == 'false'
# note using a temporary commit for build-image that works around the go get issues, replace when go get issues are fixed please
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/build-image@a2bf54158aa0a77a55f432347bc9ecf8ef642c2b # cosmos_one_off
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/build-image@2c9f401149f6c25fb632067b7e6626aebeee5d69
with:
cl_repo: smartcontractkit/chainlink
# By default we are integrating with CL develop
Expand All @@ -81,9 +90,10 @@ jobs:
env:
CHAINLINK_ENV_USER: ${{ github.actor }}
L2_RPC_URL: ${{ github.event.inputs.l2_rpc_url }}
TEST_DURATION: ${{ github.event.inputs.test_duration }}
NODE_COUNT: ${{ github.event.inputs.node_count }}
PRIVATE_KEY: ${{ secrets.GOERLI_PRIVATE_KEY }}
ACCOUNT: ${{ secrets.GOERLI_ACCOUNT }}
PRIVATE_KEY: ${{ github.event.inputs.private_key }}
ACCOUNT: ${{ github.event.inputs.account }}
TTL: ${{ github.event.inputs.ttl }}
DETACH_RUNNER: true
TEST_SUITE: soak
Expand All @@ -108,7 +118,7 @@ jobs:
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ACCOUNT_NUMBER: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}
- name: Run Tests
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@ce87f8986ca18336cc5015df75916c2ec0a7c4b3 # v2.1.2
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@2c9f401149f6c25fb632067b7e6626aebeee5d69 # v2.1.2
with:
test_command_to_run: nix develop -c make test-integration-soak-ci
test_download_vendor_packages_command: cd integration-tests && nix develop -c go mod download
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/integration_contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ jobs:
- name: Install Cairo
uses: ./.github/actions/install-cairo

- name: Install starknet-devnet (via venv+pip)
run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt

- name: Test
run: nix develop -c make test-integration-contracts
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ linters:
- misspell
# - rowserrcheck
- errorlint
- durationcheck
linters-settings:
exhaustive:
default-signifies-exhaustive: true
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ golang 1.20.1
python 3.9.13

# Tools
mockery 2.13.0-beta.1
mockery 2.22.1
golangci-lint 1.51.2
actionlint 1.6.12
shellcheck 0.8.0
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@ test-integration-smoke: test-integration-prep
.PHONY: test-integration-smoke-ci
test-integration-smoke-ci:
cd integration-tests/ && \
go test --timeout=2h -v -count=1 -json ./smoke 2>&1 | tee /tmp/gotest.log | gotestfmt
go test --timeout=2h -v -count=1 -json ./smoke

.PHONY: test-integration-soak
test-integration-soak: test-integration-prep
cd integration-tests/ && \
go test --timeout=1h -v ./soak
go test --timeout=1h -v -json./soak

# CI Already has already ran test-integration-prep
.PHONY: test-integration-soak-ci
test-integration-soak-ci:
cd integration-tests/ && \
go test --timeout=1h -v -count=1 -json ./soak 2>&1 | tee /tmp/gotest.log | gotestfmt
go test --timeout=1h -v -count=1 -json ./soak

.PHONY: test-integration-contracts
# TODO: better network lifecycle setup - requires external network (L1 + L2)
Expand Down Expand Up @@ -257,7 +257,7 @@ test-integration-gauntlet: build-ts env-devnet-hardhat-down
test-ts: test-ts-contracts test-integration-contracts test-integration-gauntlet

.PHONY: test-ts-contracts
test-ts-contracts: build-sol-contracts build-ts-workspace env-devnet-hardhat
test-ts-contracts: build-ts env-devnet-hardhat
cd contracts/ && \
yarn test

Expand Down
5 changes: 4 additions & 1 deletion contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '@shardlabs/starknet-hardhat-plugin'
import '@nomiclabs/hardhat-ethers'
import '@nomicfoundation/hardhat-chai-matchers'
import 'solidity-coverage'
import { prepareHardhatArtifacts } from './test/setup'

const COMPILER_SETTINGS = {
optimizer: {
Expand Down Expand Up @@ -58,7 +59,9 @@ const config: HardhatUserConfig = {
},
mocha: {
timeout: 10000000,
file: './test/setup.ts',
rootHooks: {
beforeAll: prepareHardhatArtifacts,
},
},
paths: {
sources: './solidity',
Expand Down
3 changes: 2 additions & 1 deletion contracts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ecdsa
fastecdsa
sympy
starknet-devnet>=0.5.0
cairo-lang>=0.11.1.1
starknet-devnet>=0.5.2
6 changes: 6 additions & 0 deletions contracts/solidity/emergency/StarknetValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ contract StarknetValidator is TypeAndVersionInterface, AggregatorValidatorInterf
error InvalidL2FeedAddress();
/// @notice Error thrown when the source aggregator address is 0
error InvalidSourceAggregatorAddress();
/// @notice Error thrown when the access controller address is 0
error InvalidAccessControllerAddress();
/// @notice Error thrown when the l1 gas price feed address is 0
error InvalidGasPriceL1FeedAddress();
/// @notice Error thrown when caller is not the owner and does not have access
Expand Down Expand Up @@ -240,6 +242,10 @@ contract StarknetValidator is TypeAndVersionInterface, AggregatorValidatorInterf
* @param accessController The address of the Access Controller for this contract
*/
function _setConfigAC(address accessController) internal {
if (accessController == address(0)) {
revert InvalidAccessControllerAddress();
}

address previousAccessController = address(s_configAC);
if (accessController != previousAccessController) {
// NOTICE: we don't give access to the new source aggregator
Expand Down
11 changes: 11 additions & 0 deletions contracts/src/access_control/access_controller.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
use starknet::ContractAddress;

#[abi]
trait IAccessController {
fn has_access(user: ContractAddress, data: Array<felt252>) -> bool;
fn add_access(user: ContractAddress);
fn remove_access(user: ContractAddress);
fn enable_access_check();
fn disable_access_check();
}

#[contract]
mod AccessController {
use starknet::ContractAddress;
Expand Down
34 changes: 15 additions & 19 deletions contracts/src/emergency/sequencer_uptime_feed.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#[contract]
mod SequencerUptimeFeed {
use starknet::EthAddress;
use starknet::EthAddressSerde;
use starknet::EthAddressIntoFelt252;
use starknet::Felt252TryIntoEthAddress;
use starknet::EthAddressZeroable;
use starknet::ContractAddress;
use starknet::StorageAccess;
use starknet::StorageBaseAddress;
Expand All @@ -13,6 +18,7 @@ mod SequencerUptimeFeed {
use traits::Into;
use traits::TryInto;
use option::OptionTrait;
use zeroable::Zeroable;

use chainlink::libraries::ownable::Ownable;
use chainlink::libraries::access_control::AccessControl;
Expand All @@ -22,10 +28,8 @@ mod SequencerUptimeFeed {
use chainlink::ocr2::aggregator::Aggregator::TransmissionStorageAccess;
use chainlink::libraries::upgradeable::Upgradeable;

const ETH_ADDRESS_BOUND: felt252 = 0x10000000000000000000000000000000000000000; // 2**160

struct Storage {
// l1 sender is an ethereum address
// l1 sender is an starknet validator ethereum address
_l1_sender: felt252,
// maps round id to round transmission
_round_transmissions: LegacyMap<u128, Transmission>,
Expand All @@ -47,7 +51,7 @@ mod SequencerUptimeFeed {
) {}

#[event]
fn L1SenderTransferred(from_address: felt252, to_address: felt252) {}
fn L1SenderTransferred(from_address: EthAddress, to_address: EthAddress) {}

impl Aggregator of IAggregator {
fn latest_round_data() -> Round {
Expand Down Expand Up @@ -118,25 +122,22 @@ mod SequencerUptimeFeed {
}

#[external]
fn set_l1_sender(address: felt252) {
fn set_l1_sender(address: EthAddress) {
Ownable::assert_only_owner();

// convert both to u256 (felts don't implement PartialOrd)
assert(address.into() < ETH_ADDRESS_BOUND.into(), 'invalid eth address');

assert(address != 0, '0 address not allowed');
assert(!address.is_zero(), '0 address not allowed');

let old_address = _l1_sender::read();

if old_address != address {
_l1_sender::write(address);
L1SenderTransferred(old_address, address);
if old_address != address.into() {
_l1_sender::write(address.into());
L1SenderTransferred(old_address.try_into().unwrap(), address);
}
}

#[view]
fn l1_sender() -> felt252 {
_l1_sender::read()
fn l1_sender() -> EthAddress {
_l1_sender::read().try_into().unwrap()
}

///
Expand Down Expand Up @@ -216,11 +217,6 @@ mod SequencerUptimeFeed {
AccessControl::has_access(user, data)
}

#[view]
fn check_access(user: ContractAddress) {
AccessControl::check_access(user)
}

#[external]
fn add_access(user: ContractAddress) {
Ownable::assert_only_owner();
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/libraries/token/erc677.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ mod ERC677 {
use super::IERC677ReceiverDispatcher;
use super::IERC677ReceiverDispatcherTrait;

const IERC677_RECEIVER_ID: u32 = 0xa53f2491_u32;
// ethereum function selector of "onTokenTransfer(address,uint256,bytes)"
const IERC677_RECEIVER_ID: u32 = 0xa4c0ed36_u32;

#[event]
fn Transfer(from: ContractAddress, to: ContractAddress, value: u256, data: Array<felt252>) {}
Expand Down
Loading

0 comments on commit cfc12c8

Please sign in to comment.