Skip to content

Commit 323a191

Browse files
uri-99taturosatitaturosatiglpecileJuArce
authored
feat: add limit on aggregator spending (#910)
Co-authored-by: Santos Rosati <[email protected]> Co-authored-by: taturosati <“[email protected]”> Co-authored-by: Gian <[email protected]> Co-authored-by: taturosati <[email protected]> Co-authored-by: Tatu <[email protected]> Co-authored-by: Julian Arce <[email protected]>
1 parent 7c32f61 commit 323a191

File tree

25 files changed

+337
-652
lines changed

25 files changed

+337
-652
lines changed

.github/workflows/build-rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
build:
15-
runs-on: ubuntu-latest
15+
runs-on: aligned-runner
1616

1717
steps:
1818
- uses: actions/checkout@v4

aggregator/internal/pkg/aggregator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type BatchData struct {
4242

4343
type Aggregator struct {
4444
AggregatorConfig *config.AggregatorConfig
45-
NewBatchChan chan *servicemanager.ContractAlignedLayerServiceManagerNewBatchV2
45+
NewBatchChan chan *servicemanager.ContractAlignedLayerServiceManagerNewBatchV3
4646
avsReader *chainio.AvsReader
4747
avsSubscriber *chainio.AvsSubscriber
4848
avsWriter *chainio.AvsWriter
@@ -91,7 +91,7 @@ type Aggregator struct {
9191
}
9292

9393
func NewAggregator(aggregatorConfig config.AggregatorConfig) (*Aggregator, error) {
94-
newBatchChan := make(chan *servicemanager.ContractAlignedLayerServiceManagerNewBatchV2)
94+
newBatchChan := make(chan *servicemanager.ContractAlignedLayerServiceManagerNewBatchV3)
9595

9696
avsReader, err := chainio.NewAvsReaderFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig)
9797
if err != nil {

batcher/aligned-batcher/src/eth/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@ pub struct CreateNewTaskFeeParams {
2929
pub fee_for_aggregator: U256,
3030
pub fee_per_proof: U256,
3131
pub gas_price: U256,
32+
pub respond_to_task_fee_limit: U256,
3233
}
3334

3435
impl CreateNewTaskFeeParams {
35-
pub fn new(fee_for_aggregator: U256, fee_per_proof: U256, gas_price: U256) -> Self {
36+
pub fn new(
37+
fee_for_aggregator: U256,
38+
fee_per_proof: U256,
39+
gas_price: U256,
40+
respond_to_task_fee_limit: U256,
41+
) -> Self {
3642
CreateNewTaskFeeParams {
3743
fee_for_aggregator,
3844
fee_per_proof,
3945
gas_price,
46+
respond_to_task_fee_limit,
4047
}
4148
}
4249
}
@@ -97,6 +104,7 @@ pub async fn try_create_new_task(
97104
signatures,
98105
fee_params.fee_for_aggregator,
99106
fee_params.fee_per_proof,
107+
fee_params.respond_to_task_fee_limit,
100108
)
101109
.gas_price(fee_params.gas_price);
102110

batcher/aligned-batcher/src/lib.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ pub mod types;
5151
mod zk_utils;
5252

5353
const AGGREGATOR_GAS_COST: u128 = 400_000;
54-
const BATCHER_SUBMISSION_BASE_GAS_COST: u128 = 100_000;
54+
const BATCHER_SUBMISSION_BASE_GAS_COST: u128 = 125_000;
5555
const ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF: u128 = 13_000;
56-
const CONSTANT_GAS_COST: u128 = AGGREGATOR_GAS_COST + BATCHER_SUBMISSION_BASE_GAS_COST;
56+
const CONSTANT_GAS_COST: u128 = ((AGGREGATOR_GAS_COST * DEFAULT_AGGREGATOR_FEE_MULTIPLIER)
57+
/ DEFAULT_AGGREGATOR_FEE_DIVIDER)
58+
+ BATCHER_SUBMISSION_BASE_GAS_COST;
5759
const DEFAULT_MAX_FEE_PER_PROOF: u128 = ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * 100_000_000_000; // gas_price = 100 Gwei = 0.0000001 ether (high gas price)
5860
const MIN_FEE_PER_PROOF: u128 = ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * 100_000_000; // gas_price = 0.1 Gwei = 0.0000000001 ether (low gas price)
61+
const RESPOND_TO_TASK_FEE_LIMIT_MULTIPLIER: u128 = 5; // to set the respondToTaskFeeLimit variable higher than fee_for_aggregator
62+
const RESPOND_TO_TASK_FEE_LIMIT_DIVIDER: u128 = 2;
63+
const DEFAULT_AGGREGATOR_FEE_MULTIPLIER: u128 = 3; // to set the feeForAggregator variable higher than what was calculated
64+
const DEFAULT_AGGREGATOR_FEE_DIVIDER: u128 = 2;
5965

6066
struct BatchState {
6167
batch_queue: BatchQueue,
@@ -1085,9 +1091,19 @@ impl Batcher {
10851091
/ num_proofs_in_batch as u128;
10861092

10871093
let fee_per_proof = U256::from(gas_per_proof) * gas_price;
1088-
let fee_for_aggregator = U256::from(AGGREGATOR_GAS_COST) * gas_price;
1089-
1090-
let fee_params = CreateNewTaskFeeParams::new(fee_for_aggregator, fee_per_proof, gas_price);
1094+
let fee_for_aggregator = (U256::from(AGGREGATOR_GAS_COST)
1095+
* gas_price
1096+
* U256::from(DEFAULT_AGGREGATOR_FEE_MULTIPLIER))
1097+
/ U256::from(DEFAULT_AGGREGATOR_FEE_DIVIDER);
1098+
let respond_to_task_fee_limit = (fee_for_aggregator
1099+
* U256::from(RESPOND_TO_TASK_FEE_LIMIT_MULTIPLIER))
1100+
/ U256::from(RESPOND_TO_TASK_FEE_LIMIT_DIVIDER);
1101+
let fee_params = CreateNewTaskFeeParams::new(
1102+
fee_for_aggregator,
1103+
fee_per_proof,
1104+
gas_price,
1105+
respond_to_task_fee_limit,
1106+
);
10911107

10921108
let signatures = signatures
10931109
.iter()

batcher/aligned-sdk/abi/AlignedLayerServiceManager.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

batcher/aligned-sdk/abi/BatcherPaymentService.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

batcher/aligned-sdk/src/eth/aligned_service_manager.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ use crate::core::errors::VerificationError;
77

88
abigen!(
99
AlignedLayerServiceManagerContract,
10-
"abi/AlignedLayerServiceManager.json"
10+
"abi/AlignedLayerServiceManager.json",
11+
methods {
12+
verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256) as verify_batch_inclusion_legacy;
13+
verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256,address) as verify_batch_inclusion;
14+
},
1115
);
1216

1317
type AlignedLayerServiceManager = AlignedLayerServiceManagerContract<Provider<Http>>;

contracts/bindings/AlignedLayerServiceManager/binding.go

Lines changed: 178 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/scripts/anvil/deploy_aligned_contracts.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ forge_output=$(forge script script/deploy/BatcherPaymentServiceDeployer.s.sol \
4848
batcher_payment_service_proxy=$(echo "$forge_output" | awk '/0: address/ {print $3}')
4949
batcher_payment_service_implementation=$(echo "$forge_output" | awk '/1: address/ {print $3}')
5050

51+
# Give initial funds to ServiceManager for the Batcher
52+
cast send $ALIGNED_LAYER_SERVICE_MANAGER_ADDRESS "depositToBatcher(address)()" $batcher_payment_service_proxy --value 1ether --private-key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" --rpc-url "http://localhost:8545"
53+
5154
# Use the extracted value to replace the batcher payment service values in alignedlayer_deployment_output.json and save it to a temporary file
5255
jq --arg batcher_payment_service_proxy "$batcher_payment_service_proxy" '.addresses.batcherPaymentService = $batcher_payment_service_proxy' "script/output/devnet/alignedlayer_deployment_output.json" > "script/output/devnet/alignedlayer_deployment_output.temp1.json"
5356
jq --arg batcher_payment_service_implementation "$batcher_payment_service_implementation" '.addresses.batcherPaymentServiceImplementation = $batcher_payment_service_implementation' "script/output/devnet/alignedlayer_deployment_output.temp1.json" > "script/output/devnet/alignedlayer_deployment_output.temp2.json"

contracts/scripts/anvil/state/alignedlayer-deployed-anvil-state.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)