Skip to content

Commit d01d682

Browse files
authored
feat(vapp): remove VAppStateContainer addresses (#174)
1 parent a459209 commit d01d682

File tree

7 files changed

+60
-71
lines changed

7 files changed

+60
-71
lines changed

crates/vapp/src/errors.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ pub enum VAppPanic {
7979
)]
8080
ProverDelegatedSignerMismatch { prover: Address, delegated_signer: Address },
8181

82-
#[error("Auctioneer mismatch: request_auctioneer={request_auctioneer}, settle_signer={settle_signer}, auctioneer={auctioneer}")]
83-
AuctioneerMismatch { request_auctioneer: Address, settle_signer: Address, auctioneer: Address },
82+
#[error("Auctioneer mismatch: request_auctioneer={request_auctioneer}, settle_signer={settle_signer}")]
83+
AuctioneerMismatch { request_auctioneer: Address, settle_signer: Address },
8484

85-
#[error("Executor mismatch: request_executor={request_executor}, execute_signer={execute_signer}, executor={executor}")]
86-
ExecutorMismatch { request_executor: Address, execute_signer: Address, executor: Address },
85+
#[error(
86+
"Executor mismatch: request_executor={request_executor}, execute_signer={execute_signer}"
87+
)]
88+
ExecutorMismatch { request_executor: Address, execute_signer: Address },
8789

8890
#[error("Address deserialization failed")]
8991
AddressDeserializationFailed,

crates/vapp/src/sol.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ sol! {
101101
bytes32 accountsRoot;
102102
bytes32 transactionsRoot;
103103
address treasury;
104-
address auctioneer;
105-
address executor;
106-
address verifier;
107104
}
108105

109106
/// @notice The account data for Merkle tree leaves.

crates/vapp/src/state.rs

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,6 @@ pub struct VAppState<A: Storage<Address, Account>, R: Storage<RequestId, bool>>
6161
///
6262
/// Fees earned by the protocol are sent to this address.
6363
pub treasury: Address,
64-
/// The auctioneer address.
65-
///
66-
/// This is a trusted party that matches requests to provers.
67-
pub auctioneer: Address,
68-
/// The executor address.
69-
///
70-
/// This is a trusted party that executes the requests and provides auxiliary information.
71-
pub executor: Address,
72-
/// The verifier address.
73-
///
74-
/// This is a trusted party that verifies the proof and provides auxiliary information.
75-
pub verifier: Address,
7664
}
7765

7866
impl VAppState<MerkleStorage<Address, Account>, MerkleStorage<RequestId, bool>> {
@@ -87,9 +75,6 @@ impl VAppState<MerkleStorage<Address, Account>, MerkleStorage<RequestId, bool>>
8775
accountsRoot: self.accounts.root(),
8876
transactionsRoot: self.transactions.root(),
8977
treasury: self.treasury,
90-
auctioneer: self.auctioneer,
91-
executor: self.executor,
92-
verifier: self.verifier,
9378
};
9479
H::hash(&state)
9580
}
@@ -108,9 +93,6 @@ impl VAppState<SparseStorage<Address, Account>, SparseStorage<RequestId, bool>>
10893
accountsRoot: account_root,
10994
transactionsRoot: transactions_root,
11095
treasury: self.treasury,
111-
auctioneer: self.auctioneer,
112-
executor: self.executor,
113-
verifier: self.verifier,
11496
};
11597
H::hash(&state)
11698
}
@@ -119,13 +101,7 @@ impl VAppState<SparseStorage<Address, Account>, SparseStorage<RequestId, bool>>
119101
impl<A: Storage<Address, Account>, R: Storage<RequestId, bool>> VAppState<A, R> {
120102
/// Creates a new [`VAppState`].
121103
#[must_use]
122-
pub fn new(
123-
domain: B256,
124-
treasury: Address,
125-
auctioneer: Address,
126-
executor: Address,
127-
verifier: Address,
128-
) -> Self {
104+
pub fn new(domain: B256, treasury: Address) -> Self {
129105
Self {
130106
domain,
131107
tx_id: 1,
@@ -135,9 +111,6 @@ impl<A: Storage<Address, Account>, R: Storage<RequestId, bool>> VAppState<A, R>
135111
accounts: A::new(),
136112
transactions: R::new(),
137113
treasury,
138-
auctioneer,
139-
executor,
140-
verifier,
141114
}
142115
}
143116

@@ -705,22 +678,17 @@ impl<A: Storage<Address, Account>, R: Storage<RequestId, bool>> VAppState<A, R>
705678

706679
// Validate that the request, settle, and auctioneer addresses match.
707680
let request_auctioneer = address(request.auctioneer.as_slice())?;
708-
if !(request_auctioneer == settle_signer && settle_signer == self.auctioneer) {
681+
if request_auctioneer != settle_signer {
709682
return Err(VAppPanic::AuctioneerMismatch {
710683
request_auctioneer,
711684
settle_signer,
712-
auctioneer: self.auctioneer,
713685
});
714686
}
715687

716688
// Validate that the request, execute, and executor addresses match.
717689
let request_executor = address(request.executor.as_slice())?;
718-
if !(request_executor == execute_signer && request_executor == self.executor) {
719-
return Err(VAppPanic::ExecutorMismatch {
720-
request_executor,
721-
execute_signer,
722-
executor: self.executor,
723-
});
690+
if request_executor != execute_signer {
691+
return Err(VAppPanic::ExecutorMismatch { request_executor, execute_signer });
724692
}
725693

726694
// Ensure that the bid price is less than the max price per pgu.
@@ -866,7 +834,7 @@ impl<A: Storage<Address, Account>, R: Storage<RequestId, bool>> VAppState<A, R>
866834
.hash_with_signer(fulfill_signer.as_slice())
867835
.map_err(|_| VAppPanic::HashingBodyFailed)?;
868836
let verifier = eth_sign_verify(&fulfillment_id, verify)?;
869-
if verifier != self.verifier {
837+
if verifier != address(request.verifier.as_slice())? {
870838
return Err(VAppPanic::InvalidVerifierSignature);
871839
}
872840
}

crates/vapp/tests/clear.rs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,12 +1762,14 @@ fn test_clear_auctioneer_mismatch_global() {
17621762
let create_prover_tx = create_prover_tx(prover_address, prover_address, U256::ZERO, 1, 2, 2);
17631763
test.state.execute::<MockVerifier>(&create_prover_tx).unwrap();
17641764

1765-
// For this test, we need to modify the request's auctioneer field.
1766-
let clear_tx = create_clear_tx(
1765+
// Create a clear transaction where the request specifies test.auctioneer
1766+
// but the settle is signed by a different signer.
1767+
let clear_tx = create_clear_tx_with_mismatched_auctioneer(
17671768
&test.requester,
17681769
&test.fulfiller,
17691770
&test.fulfiller,
1770-
&signer("different_auctioneer"),
1771+
&test.auctioneer, // Expected auctioneer in request
1772+
&signer("different_auctioneer"), // Wrong settle signer
17711773
&test.executor,
17721774
&test.verifier,
17731775
1,
@@ -1801,14 +1803,14 @@ fn test_clear_executor_mismatch_request() {
18011803
let create_prover_tx = create_prover_tx(prover_address, prover_address, U256::ZERO, 1, 2, 2);
18021804
test.state.execute::<MockVerifier>(&create_prover_tx).unwrap();
18031805

1804-
// Create clear transaction where execute signer != request executor.
1806+
// Create clear transaction with correct executor in request but wrong execute signer.
18051807
let wrong_executor = signer("wrong_executor");
1806-
let clear_tx = create_clear_tx(
1808+
let mut clear_tx = create_clear_tx(
18071809
&test.requester,
18081810
&test.fulfiller,
18091811
&test.fulfiller,
18101812
&test.auctioneer,
1811-
&wrong_executor, // Wrong executor as execute signer
1813+
&test.executor,
18121814
&test.verifier,
18131815
1,
18141816
U256::from(50_000),
@@ -1821,6 +1823,13 @@ fn test_clear_executor_mismatch_request() {
18211823
false,
18221824
);
18231825

1826+
// Replace the execute signature with wrong signer.
1827+
if let VAppTransaction::Clear(ref mut clear) = clear_tx {
1828+
if let Some(ref execute_body) = clear.execute.body {
1829+
clear.execute.signature = proto_sign(&wrong_executor, execute_body).as_bytes().to_vec();
1830+
}
1831+
}
1832+
18241833
// Execute should fail with ExecutorMismatch.
18251834
let result = test.state.execute::<MockVerifier>(&clear_tx);
18261835
assert!(matches!(result, Err(VAppPanic::ExecutorMismatch { .. })));
@@ -1841,13 +1850,15 @@ fn test_clear_executor_mismatch_global() {
18411850
let create_prover_tx = create_prover_tx(prover_address, prover_address, U256::ZERO, 1, 2, 2);
18421851
test.state.execute::<MockVerifier>(&create_prover_tx).unwrap();
18431852

1844-
// For this test, we need to modify the request's executor field.
1845-
let clear_tx = create_clear_tx(
1853+
// Create a clear transaction where the request specifies test.executor
1854+
// but the execute is signed by a different signer.
1855+
let different_executor = signer("different_executor");
1856+
let mut clear_tx = create_clear_tx(
18461857
&test.requester,
18471858
&test.fulfiller,
18481859
&test.fulfiller,
18491860
&test.auctioneer,
1850-
&signer("different_executor"),
1861+
&test.executor,
18511862
&test.verifier,
18521863
1,
18531864
U256::from(50_000),
@@ -1860,6 +1871,14 @@ fn test_clear_executor_mismatch_global() {
18601871
false,
18611872
);
18621873

1874+
// Replace the execute signature with different signer.
1875+
if let VAppTransaction::Clear(ref mut clear) = clear_tx {
1876+
if let Some(ref execute_body) = clear.execute.body {
1877+
clear.execute.signature =
1878+
proto_sign(&different_executor, execute_body).as_bytes().to_vec();
1879+
}
1880+
}
1881+
18631882
// Execute should fail with ExecutorMismatch.
18641883
let result = test.state.execute::<MockVerifier>(&clear_tx);
18651884
assert!(matches!(result, Err(VAppPanic::ExecutorMismatch { .. })));
@@ -2194,14 +2213,14 @@ fn test_clear_verifier_address_mismatch() {
21942213
// Create a wrong verifier signer.
21952214
let wrong_verifier = signer("wrong_verifier");
21962215

2197-
// Create clear transaction with wrong verifier signing.
2198-
let clear_tx = create_clear_tx(
2216+
// Create clear transaction with correct verifier in request but wrong verifier signing.
2217+
let mut clear_tx = create_clear_tx(
21992218
&test.requester,
22002219
&test.fulfiller,
22012220
&test.fulfiller,
22022221
&test.auctioneer,
22032222
&test.executor,
2204-
&wrong_verifier, // Wrong verifier
2223+
&test.verifier,
22052224
1,
22062225
U256::from(50_000),
22072226
1,
@@ -2213,6 +2232,15 @@ fn test_clear_verifier_address_mismatch() {
22132232
true,
22142233
);
22152234

2235+
// Replace the verifier signature with wrong signer.
2236+
if let VAppTransaction::Clear(ref mut clear) = clear_tx {
2237+
if let Some(ref fulfill) = clear.fulfill {
2238+
if let Some(ref fulfill_body) = fulfill.body {
2239+
clear.verify = Some(proto_sign(&wrong_verifier, fulfill_body).as_bytes().to_vec());
2240+
}
2241+
}
2242+
}
2243+
22162244
// Execute should fail with InvalidVerifierSignature.
22172245
let result = test.state.execute::<MockVerifier>(&clear_tx);
22182246
assert!(matches!(result, Err(VAppPanic::InvalidVerifierSignature)));

crates/vapp/tests/common/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,7 @@ pub fn setup() -> VAppTestContext {
7575
let auctioneer = signer("auctioneer");
7676
let executor = signer("executor");
7777
let verifier = signer("verifier");
78-
let state = VAppState::new(
79-
domain,
80-
treasury.address(),
81-
auctioneer.address(),
82-
executor.address(),
83-
verifier.address(),
84-
);
78+
let state = VAppState::new(domain, treasury.address());
8579
VAppTestContext {
8680
state,
8781
auctioneer,

crates/vapp/tests/delegate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn test_delegate_basic() {
1818
let prover_owner = test.signers[0].clone();
1919
let prover_address = test.signers[1].address();
2020
let delegate_address = test.signers[2].address();
21-
let auctioneer = test.state.auctioneer;
21+
let auctioneer = test.auctioneer.address();
2222

2323
// Create prover first.
2424
let create_prover_tx =
@@ -85,7 +85,7 @@ fn test_delegate_multiple_delegations() {
8585
let delegate1 = test.signers[2].address();
8686
let delegate2 = test.signers[3].address();
8787
let delegate3 = test.signers[4].address();
88-
let auctioneer = test.state.auctioneer;
88+
let auctioneer = test.auctioneer.address();
8989

9090
// Create prover first.
9191
let create_prover_tx =
@@ -442,7 +442,7 @@ fn test_delegate_exact_balance() {
442442
let prover_owner = test.signers[0].clone();
443443
let prover_address = test.signers[1].address();
444444
let delegate_address = test.signers[2].address();
445-
let auctioneer = test.state.auctioneer;
445+
let auctioneer = test.auctioneer.address();
446446

447447
// Create prover first.
448448
let create_prover_tx =

crates/vapp/tests/withdraw.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::common::*;
99
fn test_withdraw_basic() {
1010
let mut test = setup();
1111
let account = test.requester.address();
12-
let auctioneer = test.state.auctioneer;
12+
let auctioneer = test.auctioneer.address();
1313

1414
// Set up initial balance with deposit (101 PROVE = 101e18 wei).
1515
let initial_balance = U256::from(101) * U256::from(10).pow(U256::from(18));
@@ -36,7 +36,7 @@ fn test_withdraw_basic() {
3636
fn test_withdraw_partial() {
3737
let mut test = setup();
3838
let account = test.requester.address();
39-
let auctioneer = test.state.auctioneer;
39+
let auctioneer = test.auctioneer.address();
4040

4141
// Set up initial balance with deposit (503 PROVE to cover 3 withdrawals with fees).
4242
let initial_balance = U256::from(503) * U256::from(10).pow(U256::from(18));
@@ -78,7 +78,7 @@ fn test_withdraw_partial() {
7878
fn test_withdraw_exact_balance() {
7979
let mut test = setup();
8080
let account = test.requester.address();
81-
let auctioneer = test.state.auctioneer;
81+
let auctioneer = test.auctioneer.address();
8282

8383
// Set up initial balance with deposit (790 PROVE).
8484
let initial_balance = U256::from(790) * U256::from(10).pow(U256::from(18));
@@ -151,7 +151,7 @@ fn test_withdraw_prover_self_withdraw() {
151151
let mut test = setup();
152152
let prover_address = test.fulfiller.address();
153153
let prover_owner = test.requester.address();
154-
let auctioneer = test.state.auctioneer;
154+
let auctioneer = test.auctioneer.address();
155155

156156
// Create a prover with owner different from prover address.
157157
let create_tx = create_prover_tx(prover_address, prover_owner, U256::from(500), 0, 1, 1);
@@ -189,7 +189,7 @@ fn test_withdraw_third_party_for_prover() {
189189
let prover_address = test.fulfiller.address();
190190
let prover_owner = test.requester.address();
191191
let third_party = test.signers[0].clone(); // Third party who will sign the withdraw
192-
let auctioneer = test.state.auctioneer;
192+
let auctioneer = test.auctioneer.address();
193193

194194
// Create a prover with owner different from prover address.
195195
let create_tx = create_prover_tx(prover_address, prover_owner, U256::from(500), 0, 1, 1);

0 commit comments

Comments
 (0)