Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
benchmark
code-generation
transaction-code-generation
execution-grounded-evaluation
blockchain
evm
License:
File size: 6,586 Bytes
edbc049 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | """
Validator for query_nft_token_uri atomic problem.
Validates that the LLM correctly queries ERC721 NFT token URI.
"""
from typing import Dict, Any
class QueryNFTTokenURIValidator:
"""Validator for ERC721 NFT token URI query operations"""
def __init__(
self,
nft_address: str,
token_id: int
):
"""
Initialize validator with NFT query parameters.
Args:
nft_address: ERC721 NFT contract address
token_id: NFT token ID to query
"""
self.nft_address = nft_address.lower()
self.token_id = token_id
def validate(
self,
tx: Dict[str, Any],
receipt: Dict[str, Any],
state_before: Dict[str, Any],
state_after: Dict[str, Any]
) -> Dict[str, Any]:
"""
Validate the NFT token URI query result.
Scoring:
- Query execution success: 40 points
- Return format correctness: 30 points
- Token URI format validation: 30 points
Args:
tx: Transaction object (for queries, this contains the query result)
receipt: Transaction receipt (not used for queries)
state_before: Chain state before execution (contains actual token URI if available)
state_after: Not used for query operations
Returns:
Validation result with score and feedback
"""
# For query operations, the query result is in 'tx'
query_result = tx.get('query_result', {})
score = 0
max_score = 100
checks = []
feedback_parts = []
# Get expected token URI from state_before if set by quest_executor
expected_token_uri = state_before.get('token_uri')
# Check 1: Query execution success (40 points)
query_success = query_result.get('success', False)
error_msg = query_result.get('error', '')
if query_success:
score += 40
checks.append({
'name': 'Query Execution Success',
'passed': True,
'message': 'Query executed successfully'
})
else:
checks.append({
'name': 'Query Execution Success',
'passed': False,
'message': f"Query execution failed: {error_msg}"
})
return {
'passed': False,
'score': score,
'max_score': max_score,
'checks': checks,
'feedback': '❌ Query execution failed'
}
# Extract data from query result
data = query_result.get('data', {})
# Check 2: Return format correctness (30 points)
required_fields = ['tokenURI']
missing_fields = [field for field in required_fields if field not in data]
if not missing_fields:
score += 30
checks.append({
'name': 'Return Format Correct',
'passed': True,
'message': f'All required fields present: {required_fields}'
})
else:
checks.append({
'name': 'Return Format Correct',
'passed': False,
'message': f'Missing required fields: {missing_fields}'
})
feedback_parts.append(f"⚠️ Missing fields: {', '.join(missing_fields)}")
# Check 3: Token URI format validation (30 points)
try:
returned_token_uri = data.get('tokenURI', '')
# Check if it's a non-empty string
if isinstance(returned_token_uri, str) and len(returned_token_uri) > 0:
# If we have expected token URI, check if it matches
if expected_token_uri is not None:
if returned_token_uri == expected_token_uri:
score += 30
checks.append({
'name': 'Token URI Format Validation',
'passed': True,
'message': f'Token URI correct: {returned_token_uri[:100]}{"..." if len(returned_token_uri) > 100 else ""}'
})
feedback_parts.append("✅ Token URI queried correctly!")
else:
checks.append({
'name': 'Token URI Format Validation',
'passed': False,
'message': f'Token URI mismatch - Expected: {expected_token_uri[:50]}..., Got: {returned_token_uri[:50]}...'
})
feedback_parts.append(f"⚠️ Token URI mismatch")
else:
# No expected value, just validate it's a non-empty string
score += 30
checks.append({
'name': 'Token URI Format Validation',
'passed': True,
'message': f'Token URI is valid non-empty string: {returned_token_uri[:100]}{"..." if len(returned_token_uri) > 100 else ""}'
})
feedback_parts.append("✅ Token URI format valid!")
else:
checks.append({
'name': 'Token URI Format Validation',
'passed': False,
'message': f'Token URI must be a non-empty string, got: {type(returned_token_uri).__name__}'
})
feedback_parts.append(f"❌ Invalid token URI format")
except (KeyError, TypeError) as e:
checks.append({
'name': 'Token URI Format Validation',
'passed': False,
'message': f'Failed to parse token URI: {str(e)}'
})
feedback_parts.append(f"❌ Failed to parse token URI: {str(e)}")
# Generate final feedback
if score == max_score:
feedback = "🎉 Congratulations! NFT token URI queried correctly!"
elif score >= 60:
feedback = "✅ Query mostly correct. " + " ".join(feedback_parts)
else:
feedback = "❌ Query needs improvement. " + " ".join(feedback_parts)
return {
'passed': score >= 60, # Pass threshold: 60%
'score': score,
'max_score': max_score,
'checks': checks,
'feedback': feedback
}
|