Skip to content

Commit

Permalink
Merge pull request #408 from smartcontractkit/rm-gauntlet-examples
Browse files Browse the repository at this point in the history
Remove gauntlet example commands (we no longer use it for examples/) and fix ConfigSet parsing
  • Loading branch information
archseer authored Apr 10, 2024
2 parents a54448e + 432411e commit 6cb98ec
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 193 deletions.
11 changes: 0 additions & 11 deletions packages-ts/starknet-gauntlet-ocr2/src/commands/example/declare.ts

This file was deleted.

52 changes: 0 additions & 52 deletions packages-ts/starknet-gauntlet-ocr2/src/commands/example/deploy.ts

This file was deleted.

This file was deleted.

75 changes: 0 additions & 75 deletions packages-ts/starknet-gauntlet-ocr2/src/commands/example/inspect.ts

This file was deleted.

11 changes: 1 addition & 10 deletions packages-ts/starknet-gauntlet-ocr2/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@ import {
executeCommands as proxyExecuteCommands,
inspectionCommands as proxyInspectionCommands,
} from './proxy'
import {
executeCommands as exampleExecuteCommands,
inspectionCommands as exampleInspectionCommands,
} from './example'

export const executeCommands = [
...acExecuteCommands,
...ocr2ExecuteCommands,
...proxyExecuteCommands,
...exampleExecuteCommands,
]
export const inspectionCommands = [
...ocr2InspectionCommands,
...proxyInspectionCommands,
...exampleInspectionCommands,
]
export const inspectionCommands = [...ocr2InspectionCommands, ...proxyInspectionCommands]
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,5 @@ export const getLatestOCRConfigEvent = async (
keys: [keyFilter],
chunk_size: 10,
})
const events = chunk.events
// if no config set events found in the given block, throw error
// this should not happen if block number in latestConfigDetails is set correctly
if (events.length === 0)
throw new Error(`No ConfigSet events found in block number ${latestConfigDetails.blockNumber}`)

// assume last event found is the latest config, in the event that multiple
// set_config transactions ended up in the same block
return events[events.length - 1].data
return chunk.events
}
22 changes: 18 additions & 4 deletions packages-ts/starknet-gauntlet-ocr2/src/commands/ocr2/setConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SetConfig, encoding, SetConfigInput } from '@chainlink/gauntlet-contrac
import { decodeOffchainConfigFromEventData } from '../../lib/encoding'
import assert from 'assert'
import { getLatestOCRConfigEvent } from './inspection/configEvent'
import { BigNumberish, GetTransactionReceiptResponse } from 'starknet'

type Oracle = {
signer: string
Expand Down Expand Up @@ -136,15 +137,26 @@ const beforeExecute: BeforeExecute<SetConfigInput, ContractInput> = (
input.user.offchainConfig,
input.user.secret,
)

const newOffchainConfig = encoding.deserializeConfig(offchainConfig)

const eventData = await getLatestOCRConfigEvent(context.provider, context.contractAddress)
if (eventData.length === 0) {
const rawEvents = await getLatestOCRConfigEvent(context.provider, context.contractAddress)
if (rawEvents.length === 0) {
// if no config set events found in the given block, throw error
// this should not happen if block number in latestConfigDetails is set correctly
deps.logger.info('No previous config found, review the offchain config below:')
deps.logger.log(newOffchainConfig)
return
}
const currOffchainConfig = decodeOffchainConfigFromEventData(eventData)
// assume last event found is the latest config, in the event that multiple
// set_config transactions ended up in the same block
const events = context.contract.parseEvents({
events: rawEvents,
} as GetTransactionReceiptResponse)
const event = events[events.length - 1]['ConfigSet']
const currOffchainConfig = decodeOffchainConfigFromEventData(
event.offchain_config as BigNumberish[],
)

deps.logger.info(
'Review the proposed offchain config changes below: green - added, red - deleted.',
Expand All @@ -162,7 +174,9 @@ const afterExecute: AfterExecute<SetConfigInput, ContractInput> = (context, inpu
}
const eventData = txInfo.events[0].data

const offchainConfig = decodeOffchainConfigFromEventData(eventData)
const events = context.contract.parseEvents(txInfo)
const event = events[events.length - 1]['ConfigSet']
const offchainConfig = decodeOffchainConfigFromEventData(event.offchain_config as BigNumberish[])
try {
// remove cfg keys from user input
delete input.user.offchainConfig.configPublicKeys
Expand Down
29 changes: 5 additions & 24 deletions packages-ts/starknet-gauntlet-ocr2/src/lib/encoding.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
import { encoding } from '@chainlink/gauntlet-contracts-ocr2'
import { feltsToBytes } from '@chainlink/starknet-gauntlet'
import { BigNumberish } from 'starknet'

export const decodeOffchainConfigFromEventData = (data: string[]): encoding.OffchainConfig => {
// The ConfigSet event is defined as:
// fn ConfigSet(
// previous_config_block_number: u64, (key)
// latest_config_digest: felt252, (key)
// config_count: u64,
// oracles: Array<OracleConfig>,
// f: u8,
// onchain_config: Array<felt252>,
// offchain_config_version: u64,
// offchain_config: Array<felt252>,
//)
const oraclesLenIndex = 1
const oraclesLen = Number(BigInt(data[oraclesLenIndex]))
const oracleStructSize = 2
const fIndex = oraclesLenIndex + oraclesLen * oracleStructSize + 1
const onchainConfigLenIndex = fIndex + 1
const onchainConfigLen = Number(BigInt(data[onchainConfigLenIndex]))
const offchainConfigVersionIndex = onchainConfigLenIndex + onchainConfigLen + 1
const offchainConfigArrayLenIndex = offchainConfigVersionIndex + 1
const offchainConfigStartIndex = offchainConfigArrayLenIndex + 1

const offchainConfigFelts = data.slice(offchainConfigStartIndex)
return encoding.deserializeConfig(feltsToBytes(offchainConfigFelts))
export const decodeOffchainConfigFromEventData = (
data: BigNumberish[],
): encoding.OffchainConfig => {
return encoding.deserializeConfig(feltsToBytes(data))
}
4 changes: 2 additions & 2 deletions packages-ts/starknet-gauntlet/src/encoding/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cairo } from 'starknet'
import { BigNumberish, cairo } from 'starknet'

const CHUNK_SIZE = 31

Expand Down Expand Up @@ -28,7 +28,7 @@ export function bytesToFelts(data: Uint8Array | Buffer): string[] {

const MAX_LEN: bigint = (BigInt(1) << BigInt(54)) - BigInt(1)

export function feltsToBytes(felts: string[]): Buffer {
export function feltsToBytes(felts: BigNumberish[]): Buffer {
const data: number[] = []

if (!felts.length) {
Expand Down

0 comments on commit 6cb98ec

Please sign in to comment.