VeChain Docs
  • Welcome to VeChain
  • Blockchain Basics
    • Introduction to blockchain
    • Introduction to digital property
    • The evolution of the internet
  • Introduction to VeChain
    • About the VeChain blockchain
      • Consensus Deep Dive
      • Governance
    • Dual-Token Economic Model
      • VeChain (VET)
      • VeThor (VTHO)
    • Acquire VeChain Assets
    • Sustainability
  • Core Concepts
    • Networks
      • Thor Solo Node
      • Testnet
      • Mainnet
    • Nodes
      • Node Rewards Programme
    • Blocks
      • Block Model
    • Transactions
      • Transaction Model
      • Transaction Fees
      • Transaction Calculation
      • Meta Transaction Features
        • Transaction Uniqueness
        • Controllable Transaction Lifecycle
        • Clauses (Multi-Task Transaction)
        • Fee Delegation
          • Multi-Party Payment (MPP)
          • Designated Gas Payer (VIP-191)
        • Transaction Dependency
    • Block Explorers
    • Wallets
      • VeWorld
        • User Guide
          • Setup
          • Wallet
          • Signing
          • Activities
          • Settings
        • FAQ
      • Sync2
        • User Guide
          • Setup
          • Wallet
          • Signing
          • Activities
          • Settings
        • FAQ
      • Sync
        • User Guide
          • Wallet
          • Ledger Device
          • Browser dApps and web
          • Interact with dApps
          • Activities
          • Settings
          • Report an Issue
          • Contributing
        • FAQ
    • EVM Compatibility
      • VeChain Modifications
      • Methodology
      • Test Coverage
        • Gas model
        • Raw transaction
        • hardhat specific
          • Ganache failures
          • evm_increaseTime
        • Failures in constructor
        • eth_sign
        • Contract address prediction
        • BadBeacon proxy address at 0x1
      • How to Recreate
      • Additional Information
        • Using Governance Contracts
        • ERC1820/ERC777 Testnet
        • Delegate Options
    • Account Abstraction
      • UserOperation
      • Bundler
      • EntryPoint Contract
      • Account Factory Contract
      • Paymaster Contract
    • Token Bound Accounts
  • How to run a node
    • Nodes
    • How to run a Thor Solo Node
    • Custom Network
    • Connect Sync2 to a Thor Solo Node
  • Developer Resources
    • Getting Started
    • How to build on VeChain
      • Connect to the Network
      • Read Data
        • Read Blocks
        • Read Transactions
        • Read Accounts
        • States & Views
        • Events & Logs
        • VET Transfers
      • Write Data
        • Transactions
        • Fee Delegation
      • Listen to Changes
        • Events
        • VET Transfers
        • Transactions
        • Blocks
        • Beats
      • Build with Hardhat
      • Utilities
        • BigInt and Unit-Handling
        • Name Service Lookups
    • Example dApps
      • Buy me a Coffee
      • Token Bound Accounts
      • PWA with Privy and Account Abstraction
    • EVM Compatibility for Developers
      • Key Architectural Differences and Optimizations
      • Practical Implications for Developers: Key Considerations
      • RPC Methods (Detailed Breakdown)
      • Frequently Asked Questions (FAQs)
      • VeChain Blockchain Specifications
      • Key Differences Between VeChain and Ethereum (Summary)
      • Best Practices for Developing on VeChainThor
    • How to verify Address-Ownership
      • Next.js Session Verification
    • Debug Reverted Transactions
    • Account Abstraction
    • VIP-191: Designated Gas Payer
      • How to Integrate VIP-191 (I)
      • How to Integrate VIP-191 (II)
      • How to Integrate VIP-191 (III)
    • Index with Graph Node
      • Setup with Docker
      • Index with OpenZeppelin
        • Create Subgraph Project
        • Configure Contracts
        • Deploy Subgraph and start Indexing
        • Track Subgraph Indexing
        • Access Subgraph
        • Update Subgraph
    • SDKs & Providers
      • SDK
        • Architecture
        • Accounts
        • Bloom Filter
        • Certificates
        • Contracts
        • Cryptography
        • Debug
        • Encoding
        • Polls
        • Subscriptions
        • Thor Client
        • Transactions
      • Thor DevKit
        • Installation
        • Usage
          • Cryptography
          • Accounts
          • Encoding
          • Transactions
          • Certificates
          • Bloom Filter
      • DApp Kit
        • v2
          • Installation
          • React
            • Installation
            • Usage
          • Vanilla JS
            • Installation
            • Usage
          • Core
            • Installation
            • Usage
          • Theme Variables
          • i18n
        • v1
          • Installation
          • React
            • Installation
            • Usage
          • Vanilla JS
            • Installation
            • Usage
          • Core
            • Installation
            • Usage
          • Theme Variables
          • i18n
          • Node Polyfills
          • V0 to V1
        • v0
          • Installation
          • Usage
          • React
            • Installation
            • Usage
          • Vanilla (UI)
            • Installation
            • Usage
          • Styles (UI)
          • i18n
      • DevPal
      • Web3-Providers-Connex
        • Installation
        • Usage
      • Connex
        • Installation
        • API Specification
    • Frameworks & IDEs
      • Hardhat
      • Remix
    • Built-in Contracts
    • VORJ
    • Useful Links
  • How to contribute
Powered by GitBook
On this page
  • Description
  • Contracts Affected

Was this helpful?

  1. Core Concepts
  2. EVM Compatibility
  3. Test Coverage

eth_sign

PreviousFailures in constructorNextContract address prediction

Last updated 1 month ago

Was this helpful?

Description

The eth_sign issue arises due to the fact that VeChain and Ethereum use different hash functions, more information on this subject . This failure is justifiable as it is a design difference between the two chains. To fix the failing tests, we imported Ethereum's hash function and replaced the eth_sign method with one that generates signatures using the required hash function.

The following changes we made:

In compatProvider.ts

In web3-providers-connex/src/compatProvider.ts we changed the error response returned to the following:

.catch(err => callback(err, {
				id: payload.id,
				jsonrpc: '2.0',
				error: err
			}));

In provider.ts

In web3-providers-connex/src/provider.ts we imported hashEthMessage and bufferToHex from utils.js

import { hexToNumber, getErrMsg, toSubscription, toHex, hashEthMessage, bufferToHex } from './utils';

We also added the method eth_sign in the method map

this._methodMap['eth_sign'] = this._sign;

and defined the function in the same file

private _sign = async (params: any) => {
		if (!this.wallet || this.wallet.list.length === 0) {
			throw new Error("no wallet specified");
		}

		const address = params[0];
		const message = params[1];

		const key = this.wallet.list.find((key) => key.address == address);

		if (key === undefined) {
			throw new Error(`key undefined for address ${address}`)
		}

		const hash = hashEthMessage(message);

		if (hash === undefined) {
			throw new Error("undefined hash");
		}

		const hashStriped = hash?.substring(2);
		const buf = Buffer.from(hashStriped!, 'hex');

		const signature = await key.sign(buf);
		signature[64] += 27;

		return bufferToHex(signature);
	}

In utils.ts

In web3-providers-connex/src/utils.ts we imported keccak256 from 'thor-devkit'.

import { abi, keccak256, Transaction } from 'thor-devkit';

Then we defined two new functions hashEthMessage that hashes a string with Ethereum's hash function and a helper function bufferToHex.

export function bufferToHex(buf: Buffer) : string {
	return '0x' + buf.toString('hex');
}

export function hashEthMessage(data: string) : string {
	const messageHex = web3Utils.isHexStrict(data) ? data : web3Utils.utf8ToHex(data);
	const messageBytes = web3Utils.hexToBytes(messageHex);
	const messageBuffer = Buffer.from(messageBytes);
	const preamble = '\x19Ethereum Signed Message:\n' + messageBytes.length;
	const preambleBuffer = Buffer.from(preamble);
	const ethMessage = Buffer.concat([preambleBuffer, messageBuffer]);
	return bufferToHex(keccak256(ethMessage));

In getChainId.test.ts

The final change was in web3-providers-connex/test/web3/getChainId.test.ts where we replaced the main-net URL with the local instance of thor instead.

const net = new SimpleNet("http://127.0.0.1:8669");

Contracts Affected

Contract Name

SignatureChecker

here