English version: /en/doc/concepts/accounts-keys.html
Accounts & Keys
TL;DR
- senderは
EthSignedとIcSyntheticで導出経路が異なる。 expected_nonce_by_addressは20 bytes address前提。IcSyntheticはfromをpayloadで受け取らず、caller情報から決定される。
できること
- Eth signed txの署名senderを使う
- Principal由来sender(IcSynthetic)を使う
制約
- bytes32風の値を20 bytes addressとして扱う
EthSigned と IcSynthetic の違い
EthSigned- 署名済みraw txから sender を復元
- chain id検証を伴う
IcSynthetic- wrapperが
msg_caller()とcanister_self()を付与してTxIn::IcSyntheticとして投入 - payloadに
fromを持たない - sender導出失敗は
AddressDerivationFailed系エラーになる
- wrapperが
IcSynthetic で必ず押さえる点
submit_ic_txの入力は Candidrecord(to/value/gas_limit/nonce/max_fee_per_gas/max_priority_fee_per_gas/data)- 内部保存時の canonical bytes は
to_flag(0/1)形式 - nonce参照は
expected_nonce_by_addressを使う - 戻り値は
eth_tx_hashではなくtx_id - 実行確定は submit時点ではなく、後続blockで receipt 参照して判断する
安全な使い方
- callerに対応する20 bytesアドレスを確定する
expected_nonce_by_addressで nonce を取るsubmit_ic_txを送るget_pending(tx_id)/get_receipt(tx_id)で追跡する
pending/mempool運用ポリシーの正本は ../rpc/overview.md を参照。
落とし穴
- Principalエンコード値をそのままaddressとして投入する
expected_nonce_by_addressに20 bytes以外を渡すtx_idをeth_tx_hashと同一視する- submit成功を実行成功と誤認する
根拠
crates/ic-evm-wrapper/src/lib.rs(expected_nonce_by_address)crates/evm-core/src/tx_decode.rs(IcSynthetic/EthSigned)crates/evm-core/src/chain.rs(TxIn::IcSynthetic)README.md