In the ETH global state, a path is always the keccak256 hash of an Ethereum address^1
The storage trie's position is calculated as the keccak256 hash of the address and the storage position, both left-padded with zeros to a length of 32 bytes^2
Storage trie tree value is U256' rlp encode
Modifications to related rpc methods
eth_getProof need to provide proof of non-existence
#[tokio::test]
async fn deploy_contract() {
let wallet = MnemonicBuilder::<English>::default()
.phrase("test test test test test test test test test test test junk")
.build()
.unwrap();
let provider = Provider::<Http>::try_from("http://127.0.0.1:8000").unwrap();
let client = SignerMiddleware::new(provider.clone(), wallet.clone());
let abi = Contract::load(r#"[{"inputs":[],"name":"setStorage","outputs":[],"stateMutability":"nonpayable","type":"function"}]"#.as_bytes()).unwrap();
let bytecode: ethers::types::Bytes = Hex::from_str("0x6080604052348015600f57600080fd5b5060bc8061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063d3404b6d14602d575b600080fd5b60336035565b005b6104d260008190555061162e600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555056fea26469706673582212203031709c289be38bbf898048dbcca424c6fb9d0c0ffe3c2877c71b7b75e6174964736f6c63430008130033").unwrap().as_bytes().into();
let factory = ContractFactory::new(abi, bytecode, Arc::new(client.clone()));
let contract = factory.deploy(()).unwrap();
let mut tx = contract.legacy().tx;
let from = wallet.address();
let nonce = provider.get_transaction_count(from, None).await.unwrap();
tx.set_chain_id(0x41786f6e);
tx.set_nonce(nonce);
tx.set_gas_price(1);
tx.set_gas(30000000);
tx.set_from(from);
let signature: Signature = wallet.sign_transaction(&tx).await.unwrap();
let res = provider
.send_raw_transaction(dbg!(tx.rlp_signed(&signature)))
.await
.unwrap()
.await
.unwrap()
.expect("failed to send eth tx");
println!("Incrementer.sol has been deployed to {:?}", res);
}
#[tokio::test]
async fn call_set() {
let tx_data = super::test_abi::SetStorageCall.encode();
send_eth_tx(
"http://127.0.0.1:8000",
tx_data,
"0x5fc8d32690cc91d4c39d9d3abcbd16989f875707"
.parse()
.unwrap(),
)
.await
}
pub async fn send_eth_tx(axon_url: &str, data: Vec<u8>, to: Address) {
let provider = Provider::<Http>::try_from(axon_url).unwrap();
let wallet = MnemonicBuilder::<English>::default()
.phrase("test test test test test test test test test test test junk")
.build()
.unwrap();
let from: Address = dbg!(wallet.address());
let nonce = provider.get_transaction_count(from, None).await.unwrap();
let transaction_request = TransactionRequest::new()
.chain_id(0x41786f6e)
.to(to)
.data(data)
.from(from)
.gas_price(1)
.gas(210000)
.nonce(nonce);
let tx = Legacy(transaction_request);
let signature: Signature = wallet.sign_transaction(&tx).await.unwrap();
provider
.send_raw_transaction(tx.rlp_signed(&signature))
.await
.unwrap()
.await
.unwrap()
.expect("failed to send eth tx");
}
#[test]
fn test_hash() {
let key = "0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266".to_string()
+ "0000000000000000000000000000000000000000000000000000000000000001";
let decode = Hex::from_str(&key).unwrap();
let a = Hasher::digest(decode.as_bytes());
dbg!(Hex::encode(a).as_string());
}
What is the impact of this PR?
Breaking Change
PR relation:
Ref #
CI Settings
### **CI Usage**
**Tip**: Check the CI you want to run below, and then comment `/run-ci`.
**CI Switch**
- [x] Web3 Compatible Tests
- [x] OCT 1-5 And 12-15
- [x] OCT 6-10
- [x] OCT 11
- [x] OCT 16-19
- [x] v3 Core Tests
### **CI Description**
| CI Name | Description |
| ----------------------------------------- | ------------------------------------------------------------------------- |
| *Web3 Compatible Test* | Test the Web3 compatibility of Axon |
| *v3 Core Test* | Run the compatibility tests provided by Uniswap V3 |
| *OCT 1-5 \| 6-10 \| 11 \| 12-15 \| 16-19* | Run the compatibility tests provided by OpenZeppelin |
What this PR does / why we need it?
This PR add rlp encode for some key and value:
eth_getProof
need to provide proof of non-existenceTest
now,there is a contract:
Deploy it, contract address is
0x5fc8d32690cc91d4c39d9d3abcbd707
, then query:Call method
setStorage
via transaction, sender address is0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
,then query:Calculate the position of pos1:
result:
0xa3c1274aadd82e4d12c8004c33fb244ca686dad4fcc8957fc5668588c11d9502
View the value of this location:
View the corresponding proof:
Test related code:
What is the impact of this PR?
Breaking Change
PR relation:
CI Settings
### **CI Usage** **Tip**: Check the CI you want to run below, and then comment `/run-ci`. **CI Switch** - [x] Web3 Compatible Tests - [x] OCT 1-5 And 12-15 - [x] OCT 6-10 - [x] OCT 11 - [x] OCT 16-19 - [x] v3 Core Tests ### **CI Description** | CI Name | Description | | ----------------------------------------- | ------------------------------------------------------------------------- | | *Web3 Compatible Test* | Test the Web3 compatibility of Axon | | *v3 Core Test* | Run the compatibility tests provided by Uniswap V3 | | *OCT 1-5 \| 6-10 \| 11 \| 12-15 \| 16-19* | Run the compatibility tests provided by OpenZeppelin |
References