Adapt code to latest hackatom

This commit is contained in:
Simon Warta 2020-02-27 23:12:57 +01:00
parent f8e20921a3
commit 542939a63e
2 changed files with 8 additions and 9 deletions

View File

@ -144,7 +144,7 @@ async function executeContract(
value: {
sender: faucet.address,
contract: contractAddress,
msg: {},
msg: { release: {} },
sent_funds: [],
},
};

View File

@ -27,19 +27,18 @@ export function leb128Encode(uint: number): Uint8Array {
export function getRandomizedHackatom(): Uint8Array {
const data = Encoding.fromBase64(hackatom.data);
// TODO: this needs to be redone!
// The return value of the export function cosmwasm_api_0_6 is unused and
// can be randomized for testing.
//
// Find position of mutable bytes as follows:
// $ wasm-objdump -d contract.wasm | grep -F "cosmwasm_api_0_6" -A 1
// 00e67c func[149] <cosmwasm_api_0_6>:
// 00e67d: 41 83 0c | i32.const 1539
// 0136d2 func[198] <cosmwasm_api_0_6>:
// 0136d3: 41 83 0c | i32.const 1539
//
// In the last line, the addresses 00e67d-00e67f hold a one byte instruction
// (https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#constants-described-here)
// and a two byte value (leb128 encoded 1539)
// In the last line, the addresses [0136d3, 0136d3+1, 0136d3+2] hold a one byte instruction
// and a two byte value (leb128 encoded 1539). See also
// https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#constants-described-here.
// Any unsigned integer from 128 to 16383 is encoded to two leb128 bytes
const min = 128;
@ -47,8 +46,8 @@ export function getRandomizedHackatom(): Uint8Array {
const random = Math.floor(Math.random() * (max - min)) + min;
const bytes = leb128Encode(random);
data[0x00e67d + 1] = bytes[0];
data[0x00e67d + 2] = bytes[1];
data[0x0136d3 + 1] = bytes[0];
data[0x0136d3 + 2] = bytes[1];
return data;
}