Skip to content

Commit

Permalink
fix [Contracts] Check string length when setting publish config #15
Browse files Browse the repository at this point in the history
  • Loading branch information
jiguantong committed Oct 25, 2024
1 parent bfffd5a commit e61a4e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
4 changes: 2 additions & 2 deletions aggregator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"clear": "near contract call-function as-transaction ormpaggregator.guantong.testnet _clear_state json-args {} prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as ormpaggregator.guantong.testnet network-config testnet sign-with-legacy-keychain send",
"test": "$npm_execpath run build && ava -- ./build/ormp_aggregator.wasm",
"publish-external": "near contract call-function as-transaction ormpaggregator.guantong.testnet publish_external json-args '{\"request_id\": \"70021766616531051842153016788507494922593962344450640499185811468\",\"mpc_options\":{\"nonce\":\"2\",\"gas_limit\":\"1000000\",\"max_fee_per_gas\":\"305777608991\",\"max_priority_fee_per_gas\":\"2500000000\"}}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as guantong.testnet network-config testnet sign-with-legacy-keychain send",
"report": "near contract call-function as-transaction ormpaggregator.guantong.testnet report json-args '{\"request_id\":\"70021766616531051842153016788507494922593962344450640499185811468\",\"answers\":[{\"data_source_name\":\"test-source\",\"result\":\"test-result\"}],\"reward_address\":\"0x9F33a4809aA708d7a399fedBa514e0A0d15EfA85\"}' prepaid-gas '300.0 Tgas' attached-deposit '0.01 NEAR' sign-as guantong.testnet network-config testnet sign-with-legacy-keychain send",
"set-publish-config-event": "near contract call-function as-transaction ormpaggregator.guantong.testnet set_publish_chain_config json-args '{\"chain_id\":\"11155111\",\"xapi_address\":\"0x6984ebE378F8cb815546Cb68a98807C1fA121A81\",\"reporters_fee\":\"300\",\"publish_fee\":\"400\",\"reward_address\":\"0x9F33a4809aA708d7a399fedBa514e0A0d15EfA85\"}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as ormpaggregator.guantong.testnet network-config testnet sign-with-legacy-keychain send",
"report": "near contract call-function as-transaction ormpaggregator.guantong.testnet report json-args '{\"request_id\":\"70021766616531051842153016788507494922593962344450640499185811470\",\"answers\":[{\"data_source_name\":\"test-source\",\"result\":\"test-result\"}],\"reward_address\":\"0x9F33a4809aA708d7a399fedBa514e0A0d15EfA85\"}' prepaid-gas '300.0 Tgas' attached-deposit '1 NEAR' sign-as guantong.testnet network-config testnet sign-with-legacy-keychain send",
"set-publish-config-event": "near contract call-function as-transaction ormpaggregator.guantong.testnet set_publish_chain_config json-args '{\"chain_id\":\"11155111\",\"xapi_address\":\"0x6984ebE378F8cb815546Cb68a98807C1fA121A81\",\"reporters_fee\":\"12000000000000\",\"publish_fee\":\"2000000000000\",\"reward_address\":\"0x9F33a4809aA708d7a399fedBa514e0A0d15EfA85\"}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as ormpaggregator.guantong.testnet network-config testnet sign-with-legacy-keychain send",
"sync-publish-config": "near contract call-function as-transaction ormpaggregator.guantong.testnet sync_publish_config_to_remote json-args '{\"chain_id\": \"11155111\",\"mpc_options\":{\"nonce\":\"1\",\"gas_limit\":\"200000\",\"max_fee_per_gas\":\"305777608991\",\"max_priority_fee_per_gas\":\"2500000000\"}}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as guantong.testnet network-config testnet sign-with-legacy-keychain send",
"add-data-source": "near contract call-function as-transaction ormpaggregator.guantong.testnet add_data_source json-args '{\"name\":\"httpbin3\",\"url\":\"https://httpbin.org/anything\",\"method\":\"post\",\"headers\":{\"hello\":\"xapi\"},\"body_json\":{\"hello\":\"httpbin\"},\"result_path\":\"headers.host\",\"auth\":{\"place_path\":\"headers.Authorization\",\"value_path\":\"abcdefauth\"}}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as ormpaggregator.guantong.testnet network-config testnet sign-with-legacy-keychain send",
"remove-data-source": "near contract call-function as-transaction ormpaggregator.guantong.testnet remove_data_source json-args '{\"data_source_name\":\"httpbin\"}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as ormpaggregator.guantong.testnet network-config testnet sign-with-legacy-keychain send",
Expand Down
24 changes: 5 additions & 19 deletions aggregator/src/abstract/aggregator.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ export abstract class Aggregator extends ContractBase {
abstract set_publish_chain_config(publish_chain_config: PublishChainConfig): void;
_set_publish_chain_config(publish_chain_config: PublishChainConfig): void {
this._assert_operator();
assert(publish_chain_config.chain_id != null, "chain_id can't be null.");
assert(publish_chain_config.xapi_address != null, "xapi_address can't be null.");
assert(publish_chain_config.reporters_fee != null, "reporters_fee can't be null.");
assert(publish_chain_config.publish_fee != null, "publish_fee can't be null.");
assert(publish_chain_config.reward_address != null, "reward_address can't be null.");
assert(publish_chain_config.chain_id != null && publish_chain_config.chain_id.length <= 20, "chain_id can't be null and the length should <= 20");
assert(publish_chain_config.xapi_address != null && publish_chain_config.xapi_address.length == 42, "xapi_address can't be null and the length should be 42.");
assert(publish_chain_config.reporters_fee != null && publish_chain_config.reporters_fee.length <= 78, "reporters_fee can't be null and the length should <= 78");
assert(publish_chain_config.publish_fee != null && publish_chain_config.publish_fee.length <= 78, "publish_fee can't be null and the length should <= 78");
assert(publish_chain_config.reward_address != null && publish_chain_config.reward_address.length == 42, "reward_address can't be null and the length should be 42.");
const _publish_config = new PublishChainConfig({ ...publish_chain_config });
this.publish_chain_config_lookup.set(publish_chain_config.chain_id, _publish_config);
new SetPublishChainConfigEvent(_publish_config).emit();
Expand All @@ -350,13 +350,6 @@ export abstract class Aggregator extends ContractBase {
_sync_publish_config_to_remote({ chain_id, mpc_options }: { chain_id: ChainId, mpc_options: MpcOptions }): NearPromise {
this._check_mpc_options(mpc_options);

// assert(near.attachedDeposit() >= BigInt(this.mpc_config.attached_balance), `Attached: ${near.attachedDeposit()}, Require: ${this.mpc_config.attached_balance}`);
// let _surplus = near.attachedDeposit() - BigInt(this.mpc_config.attached_balance);
// if (_surplus > 0) {
// near.log(`refund more than required deposit ${_surplus} YOCTO to ${near.signerAccountId()}`);
// NearPromise.new(near.signerAccountId()).transfer(_surplus);
// }

const _latest_config = this.publish_chain_config_lookup.get(chain_id);
assert(_latest_config != null, `No publish chain config for ${chain_id}`);

Expand Down Expand Up @@ -638,13 +631,6 @@ export abstract class Aggregator extends ContractBase {
_publish({ request_id, mpc_options }: { request_id: RequestId, mpc_options: MpcOptions }): NearPromise {
this._check_mpc_options(mpc_options);

// assert(near.attachedDeposit() >= BigInt(this.mpc_config.attached_balance), `Attached: ${near.attachedDeposit()}, Require: ${this.mpc_config.attached_balance}`);
// let _surplus = near.attachedDeposit() - BigInt(this.mpc_config.attached_balance);
// if (_surplus > 0) {
// near.log(`refund more than required deposit ${_surplus} YOCTO to ${near.signerAccountId()}`);
// NearPromise.new(near.signerAccountId()).transfer(_surplus);
// }

const _response = this.response_lookup.get(request_id);
assert(_response != null, `Response for ${request_id} does not exist`);
assert(_response.status == RequestStatus[RequestStatus.AGGREGATED] || _response.status == RequestStatus[RequestStatus.PUBLISHED], `Response status is ${_response.status}, can't be published`);
Expand Down

0 comments on commit e61a4e6

Please sign in to comment.