Skip to content

Commit 3c3c289

Browse files
committed
Suport bignum in wavm
1 parent 20fd6c1 commit 3c3c289

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/wavm.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ namespace wavm_host_module {
249249
interface.top()->eeiSelfDestruct(addressOffset);
250250
}
251251

252+
// the host module is called 'bignum'
253+
DEFINE_INTRINSIC_MODULE(bignum)
254+
255+
// host functions follow
256+
DEFINE_INTRINSIC_FUNCTION(bignum, "mul256", void, mul256, U32 a, U32 b, U32 ret)
257+
{
258+
interface.top()->mul256(a, b, ret);
259+
}
260+
261+
DEFINE_INTRINSIC_FUNCTION(bignum, "umulmod256", void, umulmod246, U32 a, U32 b, U32 mod, U32 ret)
262+
{
263+
interface.top()->umulmod256(a, b, mod, ret);
264+
}
265+
252266
// this is needed for resolving names of imported host functions
253267
struct HeraWavmResolver : Runtime::Resolver {
254268
HashMap<string, Runtime::ModuleInstance*> moduleNameToInstanceMap;
@@ -349,10 +363,14 @@ ExecutionResult WavmEngine::internalExecute(
349363
Runtime::GCPointer<Runtime::ModuleInstance> ethereumHostModule = Intrinsics::instantiateModule(compartment, wavm_host_module::INTRINSIC_MODULE_REF(ethereum), "ethereum", {});
350364
heraAssert(ethereumHostModule, "Failed to create host module.");
351365

366+
Runtime::GCPointer<Runtime::ModuleInstance> bignumHostModule = Intrinsics::instantiateModule(compartment, wavm_host_module::INTRINSIC_MODULE_REF(bignum), "bignum", {});
367+
heraAssert(bignumHostModule, "Failed to create host module.");
368+
352369
// prepare contract module to resolve links against host module
353370
wavm_host_module::HeraWavmResolver resolver;
354371
// TODO: move this into the constructor?
355372
resolver.moduleNameToInstanceMap.set("ethereum", ethereumHostModule);
373+
resolver.moduleNameToInstanceMap.set("bignum", bignumHostModule);
356374
Runtime::LinkResult linkResult = Runtime::linkModule(moduleIR, resolver);
357375
ensureCondition(linkResult.success, ContractValidationFailure, "Couldn't link contract against host module.");
358376

@@ -457,7 +475,7 @@ void WavmEngine::verifyContract(bytes_view code)
457475

458476
for (auto const& import: moduleIR.functions.imports) {
459477
#if HERA_DEBUGGING
460-
if (import.moduleName == "debug")
478+
if (import.moduleName == "debug" || import.moduleName == "bignum")
461479
continue;
462480
#endif
463481

0 commit comments

Comments
 (0)