Skip to content

Commit d1a325f

Browse files
committed
feat: add RespondToTaskOld
1 parent e015126 commit d1a325f

4 files changed

Lines changed: 135 additions & 26 deletions

File tree

contracts/bindings/AlignedLayerServiceManager/binding.go

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

contracts/src/core/AlignedLayerServiceManager.sol

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,79 @@ contract AlignedLayerServiceManager is
111111
);
112112
}
113113

114+
// previous version of this function, for smooth upgradeability
115+
function respondToTask_old(
116+
// Root is signed as a way to verify the batch was right
117+
bytes32 batchMerkleRoot,
118+
NonSignerStakesAndSignature memory nonSignerStakesAndSignature
119+
) external {
120+
// batcherAddress [address(0x7969c5eD335650692Bc04293B07F5BF2e7A673C0)] > 0, // Devnet
121+
// batcherAddress [address(0x7577Ec4ccC1E6C529162ec8019A49C13F6DAd98b)] > 0, // Stage
122+
// batcherAddress [address(0x815aeCA64a974297942D2Bbf034ABEe22a38A003)] > 0, // Prod
123+
address batcherAddress = address(0x7969c5eD335650692Bc04293B07F5BF2e7A673C0);
124+
uint256 initialGasLeft = gasleft();
125+
126+
/* CHECKING SIGNATURES & WHETHER THRESHOLD IS MET OR NOT */
127+
128+
// Note: This is a hacky solidity way to see that the element exists
129+
// Value 0 would mean that the task is in block 0 so this can't happen.
130+
require(
131+
batchesState[batchMerkleRoot].taskCreatedBlock != 0,
132+
"Batch doesn't exists"
133+
);
134+
135+
// Check task hasn't been responsed yet
136+
require(
137+
batchesState[batchMerkleRoot].responded == false,
138+
"Batch already responded"
139+
);
140+
141+
require(
142+
batchersBalances[batcherAddress] > 0,
143+
"Batcher has no balance"
144+
);
145+
146+
batchesState[batchMerkleRoot].responded = true;
147+
148+
/* CHECKING SIGNATURES & WHETHER THRESHOLD IS MET OR NOT */
149+
// check that aggregated BLS signature is valid
150+
(
151+
QuorumStakeTotals memory quorumStakeTotals,
152+
bytes32 _hashOfNonSigners
153+
) = checkSignatures(
154+
batchMerkleRoot,
155+
batchesState[batchMerkleRoot].taskCreatedBlock,
156+
nonSignerStakesAndSignature
157+
);
158+
159+
// check that signatories own at least a threshold percentage of each quourm
160+
require(
161+
quorumStakeTotals.signedStakeForQuorum[0] * THRESHOLD_DENOMINATOR >=
162+
quorumStakeTotals.totalStakeForQuorum[0] *
163+
QUORUM_THRESHOLD_PERCENTAGE,
164+
"Signatories do not own at least threshold percentage of a quorum"
165+
);
166+
167+
emit BatchVerified(batchMerkleRoot, batcherAddress);
168+
169+
// Calculate estimation of gas used, check that batcher has sufficient funds
170+
// and send transaction cost to aggregator.
171+
uint256 finalGasLeft = gasleft();
172+
// 70k was measured by trial and error until the aggregator got paid a bit over what it needed
173+
uint256 txCost = (initialGasLeft - finalGasLeft + 70000) * tx.gasprice;
174+
175+
require(
176+
batchersBalances[batcherAddress] >=
177+
txCost,
178+
"Batcher has not sufficient funds for paying this transaction"
179+
);
180+
181+
batchersBalances[
182+
batcherAddress
183+
] -= txCost;
184+
payable(msg.sender).transfer(txCost);
185+
}
186+
114187
function respondToTask(
115188
// (batchMerkleRoot,senderAddress) is signed as a way to verify the batch was right
116189
bytes32 batchMerkleRoot,

contracts/src/core/IAlignedLayerServiceManager.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ interface IAlignedLayerServiceManager {
99
string calldata batchDataPointer
1010
) external payable;
1111

12+
// old respondToTask for smooth upgradeability:
13+
function respondToTask_old(
14+
bytes32 batchMerkleRoot,
15+
IBLSSignatureChecker.NonSignerStakesAndSignature
16+
memory nonSignerStakesAndSignature
17+
) external;
18+
1219
function respondToTask(
1320
bytes32 batchMerkleRoot,
1421
address senderAddress,

core/chainio/avs_writer.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,35 @@ func (w *AvsWriter) SendTask(context context.Context, batchMerkleRoot [32]byte,
8686
return nil
8787
}
8888

89+
func (w *AvsWriter) SendAggregatedResponse_old(batchMerkleRoot [32]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature) (*common.Hash, error) {
90+
txOpts := *w.Signer.GetTxOpts()
91+
txOpts.NoSend = true // simulate the transaction
92+
tx, err := w.AvsContractBindings.ServiceManager.RespondToTaskOld(&txOpts, batchMerkleRoot, nonSignerStakesAndSignature)
93+
if err != nil {
94+
// Retry with fallback
95+
tx, err = w.AvsContractBindings.ServiceManagerFallback.RespondToTaskOld(&txOpts, batchMerkleRoot, nonSignerStakesAndSignature)
96+
if err != nil {
97+
return nil, err
98+
}
99+
}
100+
101+
// Send the transaction
102+
txOpts.NoSend = false
103+
txOpts.GasLimit = tx.Gas() * 110 / 100 // Add 10% to the gas limit
104+
tx, err = w.AvsContractBindings.ServiceManager.RespondToTaskOld(&txOpts, batchMerkleRoot, nonSignerStakesAndSignature)
105+
if err != nil {
106+
// Retry with fallback
107+
tx, err = w.AvsContractBindings.ServiceManagerFallback.RespondToTaskOld(&txOpts, batchMerkleRoot, nonSignerStakesAndSignature)
108+
if err != nil {
109+
return nil, err
110+
}
111+
}
112+
113+
txHash := tx.Hash()
114+
115+
return &txHash, nil
116+
}
117+
89118
func (w *AvsWriter) SendAggregatedResponse(batchMerkleRoot [32]byte, senderAddress [20]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature) (*common.Hash, error) {
90119
txOpts := *w.Signer.GetTxOpts()
91120
txOpts.NoSend = true // simulate the transaction

0 commit comments

Comments
 (0)